Files
        @ 5e28ba3945f7
    
        
              Branch filter: 
        
    Location: ATITD-Tools/Desert-Paint-Codex/Util/FileUtils.cs - annotation
        
            
            5e28ba3945f7
            2.7 KiB
            text/x-csharp
        
        
    
    Recipe count is now a ulong instead of an int so it can show values > 2.47 billion. Also, don't allow clearing the recipe list while the recipe generator is running.
    | 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 3a27dc4b067f 3a27dc4b067f 40eaee10ae56 3a27dc4b067f 3a27dc4b067f 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 | using System;
namespace DesertPaintCodex.Util
{
    internal static class FileUtils
    {
        public static string AppDataPath =>
            System.IO.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                "DesertPaintCodex");
        public static string? FindApplicationResourceDirectory(string dirName)
        {
            return FindApplicationResource(dirName, System.IO.Directory.Exists);
        }
        public static string? FindApplicationResourceFile(string fileName)
        {
            return FindApplicationResource(fileName, System.IO.File.Exists);
        }
        private static string? FindApplicationResource(string path, Func<string?, bool> verify)
        {
            string resultPath;
            
            // string? appPath =
            //    System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string? appPath = System.IO.Path.GetDirectoryName(AppContext.BaseDirectory);
            
            if (appPath != null)
            {
                resultPath = System.IO.Path.Combine(appPath, path);
                if (verify(resultPath)) return resultPath;
                resultPath = System.IO.Path.Combine(appPath, "Data", path);
                if (verify(resultPath)) return resultPath;
            }
            // try "Resources/data" in case this is a Mac app bundle
            resultPath = System.IO.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.Resources), "data", path);
            if (verify(resultPath)) return resultPath;
            
            // try "Resources" in case this is a Mac app bundle
            resultPath = System.IO.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.Resources), path);
            if (verify(resultPath)) return resultPath;
            if (appPath != null)
            {
                resultPath = System.IO.Path.Combine(appPath, "Resources", "Data", path);
                if (verify(resultPath)) return resultPath;
                
                resultPath = System.IO.Path.Combine(appPath, "Resources", path);
                if (verify(resultPath)) return resultPath;
            }
            
            return null;
        }
        public static string FindNumberedFile(string baseName, string extension, string folder)
        {
            string filename = "";
            int i = 0;
            do
            {
                ++i;
                filename = System.IO.Path.Combine(folder, $"{baseName}_{i}.{extension}");
            }
            while (System.IO.File.Exists(filename));
            
            return filename;
        }
    }
}
 |