From 60eac0825ee37fc577dd6baf29ddd649d8a6bd4c Mon Sep 17 00:00:00 2001 From: "romain.quinio" Date: Sat, 28 Jul 2018 20:20:54 +0200 Subject: [PATCH] Switch gamedir to gamedir.txt --- PortraitBuilder/Program.cs | 13 +++++++------ PortraitBuilder/UI/PortraitBuilderForm.cs | 8 +++++--- PortraitBuilder/UI/Snippets.cs | 4 +++- README.md | 12 ++++++++++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/PortraitBuilder/Program.cs b/PortraitBuilder/Program.cs index 5f4a7c9..cfc9b41 100644 --- a/PortraitBuilder/Program.cs +++ b/PortraitBuilder/Program.cs @@ -38,13 +38,13 @@ static void Main(string[] args) { if (!Directory.Exists("dlc")) Directory.CreateDirectory("dlc"); - if (!File.Exists("gamedir")) { + if (!File.Exists("gamedir.txt")) { string dir = null; while (dir == null) { string ck2exePath = Snippets.OpenFileDialog("Please select the location of your CK2 game binary", "Executable (*.exe)|*.exe|Application (*.app)|*.app|All files|*", null); - if (ck2exePath == null) { + if (ck2exePath == null || ck2exePath.Length == 0) { if (MessageBox.Show("This program cannot run without data from the Crusader Kings II installation directory. \n To find the directory in Steam: right-click the game in the library, Properties / Local Files / Browse Local Files.", "Exit Application?", MessageBoxButtons.YesNo, @@ -54,7 +54,7 @@ static void Main(string[] args) { } else { dir = Path.GetDirectoryName(ck2exePath); - if (!Directory.Exists(Path.Combine(dir, "interface")) || !Directory.Exists(Path.Combine(dir, "gfx"))) { + if (dir.Length == 0 || !Directory.Exists(Path.Combine(dir, "interface")) || !Directory.Exists(Path.Combine(dir, "gfx"))) { MessageBox.Show("Are you sure you've selected Crusader Kings II game binary (CK2game.exe, ck2 or ck2.app) ? The selected folder doesn't contain expected interface/gfx data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dir = null; continue; @@ -71,10 +71,11 @@ static void Main(string[] args) { } private static void SetDir(string dir) { - Stream stream = new FileStream("gamedir", FileMode.Create); - BinaryWriter writer = new BinaryWriter(stream); + Stream stream = new FileStream("gamedir.txt", FileMode.Create); + StreamWriter writer = new StreamWriter(stream); writer.Write(dir); - stream.Close(); + writer.Flush(); + stream.Close(); } private static void StartUI(string[] args) { diff --git a/PortraitBuilder/UI/PortraitBuilderForm.cs b/PortraitBuilder/UI/PortraitBuilderForm.cs index 2d7ea3e..82b3737 100644 --- a/PortraitBuilder/UI/PortraitBuilderForm.cs +++ b/PortraitBuilder/UI/PortraitBuilderForm.cs @@ -217,9 +217,11 @@ private void unregisterCustomProperties() { } private string readGameDir() { - Stream stream = new FileStream("gamedir", FileMode.Open); - BinaryReader reader = new BinaryReader(stream); - return reader.ReadString() + Path.DirectorySeparatorChar; + Stream stream = new FileStream("gamedir.txt", FileMode.Open); + StreamReader reader = new StreamReader(stream); + String gameDir = reader.ReadToEnd(); + logger.Info("Read gamedir: " + gameDir); + return gameDir; } /// diff --git a/PortraitBuilder/UI/Snippets.cs b/PortraitBuilder/UI/Snippets.cs index 05de890..cd66cb6 100644 --- a/PortraitBuilder/UI/Snippets.cs +++ b/PortraitBuilder/UI/Snippets.cs @@ -13,8 +13,10 @@ public static string OpenFileDialog(string sTitle, string sFilter, string sRetur dFileDialog.CheckFileExists = true; dFileDialog.CheckPathExists = true; dFileDialog.Filter = sFilter; + dFileDialog.DereferenceLinks = true; - if (dFileDialog.ShowDialog() == DialogResult.OK) { + + if (dFileDialog.ShowDialog() == DialogResult.OK) { return dFileDialog.FileName; } else { return sReturn; diff --git a/README.md b/README.md index fff82a3..ba9aa1b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Travis - Mono 5.8 + Mono 5.x Travis build status @@ -39,7 +39,7 @@ See the dedicated [CK2 forum thread](https://forum.paradoxplaza.com/forum/index. ## Mono users (Linux/Mac/Windows) -- Install [Mono 5.8](http://www.mono-project.com/download/). Note: GTK# is not required. +- Install [Mono 5.x](http://www.mono-project.com/download/). Note: GTK# is not required. - Run ". PortraitBuilder" - Select your CK2 game executable (ex: ~/.local/share/Steam/SteamApps/common/Crusader Kings II/ck2 or /Users/USER/Library/Application Support/Steam/SteamApps/common/crusader kings ii/ck2.app). This value is kept into a file "gamedir". - Errors are logged to a log.txt file @@ -62,3 +62,11 @@ Main dependencies: To re-generate the Lexer/Parser from the grammar, install [Hime standalone distribution](https://bitbucket.org/cenotelie/hime/downloads/), and use the himecc command line utility: > himecc PortraitReader.gram -n PortraitBuilder.Parser + +### Using Ubunutu on Windows 10 + +Create the following symlinks to simulate a CK2 Steam installation on Unix: + +- Game files: ln -s /mnt/c/Program\ Files\ \(x86\)/Steam ~/.local/share/Steam +- Shortcut in home folder: ln -s ~/.local/share/Steam/SteamApps/common/Crusader\ Kings\ II ~/ck2 +- Mod folder: ln -s /mnt/c/Users//Documents/Paradox\ Interactive ~/.paradoxinteractive