Changeset - 3a27dc4b067f
[Not reviewed]
default
0 1 0
Tess Snider (Malkyne) - 3 years ago 2021-07-20 11:29:17
this@malkyne.org
Fixed a bug that caused data files not to load in single file release mode.
1 file changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
Util/FileUtils.cs
Show inline comments
...
 
@@ -2,51 +2,53 @@
 

	
 
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(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;
 
                
0 comments (0 inline, 0 general)