Skip to content

Commit

Permalink
Switch gamedir to gamedir.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
rquinio committed Jul 28, 2018
1 parent 3882bc8 commit 60eac08
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
13 changes: 7 additions & 6 deletions PortraitBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions PortraitBuilder/UI/PortraitBuilderForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion PortraitBuilder/UI/Snippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</tr>
<tr>
<td style="text-align:center">Travis</td>
<td>Mono 5.8</td>
<td>Mono 5.x</td>
<td style="text-align:center"><a href="https://travis-ci.org/rquinio/PortraitBuilder"><img src="https://travis-ci.org/rquinio/PortraitBuilder.svg?branch=master" alt="Travis build status" /></a></td>
</tr>
</table>
Expand All @@ -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
Expand All @@ -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/<user>/Documents/Paradox\ Interactive ~/.paradoxinteractive

0 comments on commit 60eac08

Please sign in to comment.