diff --git a/PortraitBuilder/Engine/Loader.cs b/PortraitBuilder/Engine/Loader.cs index ccf0850..a0c4a3a 100644 --- a/PortraitBuilder/Engine/Loader.cs +++ b/PortraitBuilder/Engine/Loader.cs @@ -99,7 +99,7 @@ public List LoadDLCs(Boolean clean) { } public List LoadDLCs() { - string dlcFolder = user.GameDir + "dlc" + Path.DirectorySeparatorChar; + string dlcFolder = Path.Combine(user.GameDir,"dlc"); logger.Info("Loading DLCs from " + dlcFolder); List dlcs = dlcReader.ParseFolder(dlcFolder); @@ -120,11 +120,11 @@ private void UnzipDLCs(List dlcs) { FastZip fastZip = new FastZip(); foreach (DLC dlc in dlcs) { string dlcCode = dlc.DLCFile.Replace(".dlc", ""); - string newDlcAbsolutePath = user.DlcDir + dlcCode + Path.DirectorySeparatorChar; + string newDlcAbsolutePath = Path.Combine(user.DlcDir, dlcCode); if (!Directory.Exists(newDlcAbsolutePath)) { logger.Info(string.Format("Extracting {0} to {1}", dlc.Name, newDlcAbsolutePath)); // Filter only portraits files, to gain speed/space - string fileFilter = @"interface;gfx/characters"; + string fileFilter = @"interface;gfx"+Path.DirectorySeparatorChar+"characters"; fastZip.ExtractZip(dlc.AbsolutePath, newDlcAbsolutePath, fileFilter); // In any case, create the directory, so that it is ignored for next load. diff --git a/PortraitBuilder/Parser/DLCReader.cs b/PortraitBuilder/Parser/DLCReader.cs index a4db03b..ca91159 100644 --- a/PortraitBuilder/Parser/DLCReader.cs +++ b/PortraitBuilder/Parser/DLCReader.cs @@ -23,9 +23,9 @@ public List ParseFolder(string folder) { foreach (FileInfo dlcFile in dlcFiles) { DLC dlc = Parse(dlcFile.FullName); if (dlc != null && dlc.Archive != null) { - // Note: path will be overriden when extracting the archive - dlc.AbsolutePath = folder + dlc.Archive.Replace("dlc/", ""); - dlcs.Add(dlc); + // Note: path will be overriden when extracting the archive + dlc.AbsolutePath = Path.Combine(folder, dlc.Archive.Substring("dlc".Length +1)); // Remove "dlc/" from path + dlcs.Add(dlc); } } } else { diff --git a/PortraitBuilder/Parser/ModReader.cs b/PortraitBuilder/Parser/ModReader.cs index b0765e1..4b92f96 100644 --- a/PortraitBuilder/Parser/ModReader.cs +++ b/PortraitBuilder/Parser/ModReader.cs @@ -29,7 +29,7 @@ public List ParseFolder(string folder) { try { Mod mod = Parse(modFile.FullName); if (mod != null && mod.Path != null) { - mod.AbsolutePath = folder + Path.DirectorySeparatorChar + mod.Path.Replace("mod/", ""); + mod.AbsolutePath = Path.Combine(folder, mod.Path.Substring("mod".Length + 1)); // Remove "mod/" from path mods.Add(mod); } } catch (Exception e) { diff --git a/PortraitBuilder/Parser/PortraitReader.cs b/PortraitBuilder/Parser/PortraitReader.cs index cf93393..8b8e900 100644 --- a/PortraitBuilder/Parser/PortraitReader.cs +++ b/PortraitBuilder/Parser/PortraitReader.cs @@ -36,20 +36,20 @@ public PortraitData Parse(string dir) { try { List fileNames = new List(); - if (Directory.Exists(dir + @"\interface\")) { - fileNames.AddRange(Directory.GetFiles(dir + @"\interface\", "*.gfx")); + if (Directory.Exists(Path.Combine(dir, "interface"))) { + fileNames.AddRange(Directory.GetFiles(Path.Combine(dir, "interface"), "*.gfx")); } // interface/portraits seems to be loaded after interface/, and override (cf byzantinegfx) - if (Directory.Exists(dir + @"\interface\portraits\")) { - fileNames.AddRange(Directory.GetFiles(dir + @"\interface\portraits\", "*.gfx")); + if (Directory.Exists(Path.Combine(dir, "interface", "portraits"))) { + fileNames.AddRange(Directory.GetFiles(Path.Combine(dir, "interface", "portraits"), "*.gfx")); } foreach (string fileName in fileNames) { Parse(fileName, data); } - if (Directory.Exists(dir + @"\interface\portrait_offsets\")) { - string[] offsetFileNames = Directory.GetFiles(dir + @"\interface\portrait_offsets\", "*.txt"); + if (Directory.Exists(Path.Combine(dir, "interface", "portrait_offsets"))) { + string[] offsetFileNames = Directory.GetFiles(Path.Combine(dir, "interface", "portrait_offsets"), "*.txt"); foreach (string offsetFileName in offsetFileNames) { Dictionary offsets = portraitOffsetReader.Parse(offsetFileName); data.Offsets = data.Offsets.Concat(offsets).GroupBy(d => d.Key).ToDictionary(d => d.Key, d => d.First().Value); diff --git a/PortraitBuilder/Program.cs b/PortraitBuilder/Program.cs index 767ee8e..5f4a7c9 100644 --- a/PortraitBuilder/Program.cs +++ b/PortraitBuilder/Program.cs @@ -35,8 +35,8 @@ static void Main(string[] args) { Application.ApplicationExit += new EventHandler(onExitApplication); - if (!Directory.Exists("dlc/")) - Directory.CreateDirectory("dlc/"); + if (!Directory.Exists("dlc")) + Directory.CreateDirectory("dlc"); if (!File.Exists("gamedir")) { string dir = null; diff --git a/PortraitBuilder/UI/PortraitBuilderForm.cs b/PortraitBuilder/UI/PortraitBuilderForm.cs index 9b32c91..888fb37 100644 --- a/PortraitBuilder/UI/PortraitBuilderForm.cs +++ b/PortraitBuilder/UI/PortraitBuilderForm.cs @@ -226,18 +226,33 @@ private string readGameDir() { /// Read userdir.txt in Steam directory for the path to mod dir, or default to pre-defined location /// private string readModDir(string gameDir) { - string modDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Paradox Interactive", "Crusader Kings II") + Path.DirectorySeparatorChar; + string userDir = getDefaultUserDir(); string userdirFilePath = Path.Combine(gameDir, "userdir.txt"); if(File.Exists(userdirFilePath)){ logger.Info("Reading userdir.txt to determine the mod directory."); Stream stream = new FileStream(userdirFilePath, FileMode.Open); StreamReader reader = new StreamReader(stream, Encoding.Default); - modDir = reader.ReadLine() + Path.DirectorySeparatorChar; - logger.Info("Found userdir.txt with path: " + modDir); - } - modDir = Path.Combine(modDir, "mod"); - return modDir; - } + userDir = reader.ReadLine() + Path.DirectorySeparatorChar; + logger.Info("Found userdir.txt with path: " + userDir); + } + return Path.Combine(userDir, "mod"); + } + + private string getDefaultUserDir() { + string userDir = null; + PlatformID os = System.Environment.OSVersion.Platform; + if (os == PlatformID.Win32NT || os == PlatformID.Win32Windows) { + userDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Paradox Interactive", "Crusader Kings II"); + } else if (os == PlatformID.MacOSX || (int) os == 128) { + // Environment.SpecialFolder.MyDocuments does not add /Documents/ on Mac + userDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Documents", "Paradox Interactive", "Crusader Kings II"); + } else if (os == PlatformID.Unix) { + userDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ".paradoxinteractive", "Crusader Kings II"); + } else { + logger.Error("Unkown platformID " + os); + } + return userDir; + } /// /// Entry point for re-drawing based on updated portrait. diff --git a/PortraitBuilder/app.config b/PortraitBuilder/app.config index 0eee32f..93b27b9 100644 --- a/PortraitBuilder/app.config +++ b/PortraitBuilder/app.config @@ -33,7 +33,7 @@ - +