Skip to content

Commit 346ffc4

Browse files
author
Valters
authored
Merge pull request valters-tomsons#27 from CyberFoxHax/master
Add flexible PCSX2 executable path.
2 parents ee07b4b + 66a8bff commit 346ffc4

File tree

7 files changed

+32
-30
lines changed

7 files changed

+32
-30
lines changed

Spectabis-WPF/Domain/GameProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Spectabis_WPF.Domain
66
class GameProfile
77
{
88
private static string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
9-
private static string emuDir = Properties.Settings.Default.emuDir;
9+
public static string emuDir { get { return Path.GetDirectoryName(Properties.Settings.Default.emuDir); } }
1010
private static int index = 0;
1111
private static string GlobalController = BaseDirectory + @"resources\configs\#global_controller\LilyPad.ini";
1212

Spectabis-WPF/Domain/GetGameName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Spectabis_WPF.Domain
66
{
77
class GetGameName
88
{
9-
private static string emuDir = Properties.Settings.Default.emuDir;
9+
public static string emuDir { get { return Path.GetDirectoryName(Properties.Settings.Default.emuDir); } }
1010

1111
//Returns a game name, using PCSX2 database file
1212
public static string GetName(string _path)

Spectabis-WPF/Domain/LaunchPCSX2.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ public static void LaunchGame(string game)
3434
if (_fullboot == "1") { _launchargs = _launchargs + "--fullboot "; }
3535
if (_nohacks == "1") { _launchargs = _launchargs + "--nohacks "; }
3636

37-
Console.WriteLine($"{_launchargs} {_isoDir} --cfgpath {gamePath}");
37+
Console.WriteLine($"{_launchargs} {_isoDir} --cfgpath={gamePath}");
3838

3939
//Paths in PCSX2 command arguments have to be in quotes...
4040
const string quote = "\"";
4141

4242
Process PCSX = new Process();
4343

4444
//PCSX2 Process
45-
if(File.Exists(Properties.Settings.Default.emuDir + @"\pcsx2.exe"))
45+
if(File.Exists(Properties.Settings.Default.emuDir))
4646
{
47-
PCSX.StartInfo.FileName = Properties.Settings.Default.emuDir + @"\pcsx2.exe";
48-
PCSX.StartInfo.Arguments = $"{_launchargs} {quote}{_isoDir}{quote} --cfgpath {quote}{gamePath}{quote}";
47+
PCSX.StartInfo.FileName = Properties.Settings.Default.emuDir;
48+
PCSX.StartInfo.Arguments = $"{_launchargs} {quote}{_isoDir}{quote} --cfgpath={quote}{gamePath}{quote}";
4949

5050
PCSX.Start();
5151

@@ -56,7 +56,7 @@ public static void LaunchGame(string game)
5656
}
5757
else
5858
{
59-
Console.WriteLine(Properties.Settings.Default.emuDir + @"\pcsx2.exe" + " does not exist!");
59+
Console.WriteLine(Properties.Settings.Default.emuDir + " does not exist!");
6060
}
6161

6262
}

Spectabis-WPF/Views/FirstTimeSetup.xaml.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,22 @@ private void PrimaryButton_Click(object sender, System.Windows.RoutedEventArgs e
2424
if(StepCounter == 0)
2525
{
2626
Ookii.Dialogs.Wpf.VistaOpenFileDialog emuBrowser = new Ookii.Dialogs.Wpf.VistaOpenFileDialog();
27-
emuBrowser.Filter = "PCSX2 Executable | PCSX2.exe|Executable|*.exe";
27+
emuBrowser.Filter = "PCSX2 Executable | *.exe|Executable|*.exe";
2828

2929
//Show dialog
3030
var browserResult = emuBrowser.ShowDialog();
3131
if (browserResult.Value == true)
3232
{
3333
string _result = emuBrowser.FileName;
3434

35-
//If filename contains ".exe", just in case
36-
if (_result.Contains(".exe") == false)
35+
if (_result.ToLower().Contains("pcsx2") == false || _result.ToLower().EndsWith(".exe") == false)
3736
{
3837
MessageBox.Show("Invalid file.");
3938
return;
4039
}
4140

42-
//Save selected path, remove pcsx2.exe from string
43-
Properties.Settings.Default.emuDir = _result.Replace("pcsx2.exe", string.Empty);
41+
//Save selected path, *don't* remove pcsx2.exe from string
42+
Properties.Settings.Default.emuDir = _result;
4443
Properties.Settings.Default.Save();
4544

4645
//Increment Step count

Spectabis-WPF/Views/Library.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class Library : Page
2727
{
2828

2929
//Spectabis Variables
30-
public static string emuDir = Properties.Settings.Default.emuDir;
30+
public static string emuDir { get { return Properties.Settings.Default.emuDir; } }
3131
private string GameConfigs;
3232
private string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
3333

@@ -176,7 +176,7 @@ private void boxArt_Click(object sender, MouseButtonEventArgs e)
176176
var _gameIni = new IniFile(_cfgDir + @"\spectabis.ini");
177177
var _isoDir = _gameIni.Read("isoDirectory", "Spectabis");
178178

179-
if (File.Exists(emuDir + @"\pcsx2.exe") == false)
179+
if (File.Exists(emuDir) == false)
180180
{
181181
PushSnackbar("PCSX2 installation corrupt");
182182
}
@@ -218,7 +218,7 @@ private void boxArt_Click(object sender, MouseButtonEventArgs e)
218218
if (_fullboot == "1") { _launchargs = _launchargs + "--fullboot "; }
219219
if (_nohacks == "1") { _launchargs = _launchargs + "--nohacks "; }
220220

221-
Console.WriteLine($"{_launchargs} {_isoDir} --cfgpath {_cfgDir}");
221+
Console.WriteLine($"{_launchargs} {_isoDir} --cfgpath={_cfgDir}");
222222

223223
//Copy global controller settings
224224
Console.WriteLine($"CopyGlobalProfile({clickedBoxArt.Tag.ToString()})");
@@ -228,8 +228,8 @@ private void boxArt_Click(object sender, MouseButtonEventArgs e)
228228
const string quote = "\"";
229229

230230
//PCSX2 Process
231-
PCSX.StartInfo.FileName = emuDir + @"\pcsx2.exe";
232-
PCSX.StartInfo.Arguments = $"{_launchargs} {quote}{_isoDir}{quote} --cfgpath {quote}{_cfgDir}{quote}";
231+
PCSX.StartInfo.FileName = emuDir;
232+
PCSX.StartInfo.Arguments = $"{_launchargs} {quote}{_isoDir}{quote} --cfgpath={quote}{_cfgDir}{quote}";
233233

234234
PCSX.EnableRaisingEvents = true;
235235
PCSX.Exited += new EventHandler(PCSX_Exited);
@@ -333,7 +333,7 @@ private void PCSX2ConfigureGame_Click(object sender, RoutedEventArgs e)
333333

334334
//Start PCSX2 only with --cfgpath
335335
string _cfgDir = GameConfigs + @"/" + clickedBoxArt.Tag;
336-
Process.Start(emuDir + @"\pcsx2.exe", " --cfgpath \"" + _cfgDir + "\"");
336+
Process.Start(emuDir, " --cfgpath=\"" + _cfgDir + "\"");
337337

338338
}
339339

Spectabis-WPF/Views/MainWindow.xaml.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Collections.Generic;
34
using System.Globalization;
45
using System.IO;
@@ -584,8 +585,9 @@ private void CopyShaders(string currentGame)
584585

585586
if(File.Exists(GSdxfx) == false)
586587
{
587-
File.Copy(Properties.Settings.Default.emuDir + @"\shaders\GSdx.fx", GSdxfx);
588-
File.Copy(Properties.Settings.Default.emuDir + @"\shaders\GSdx_FX_Settings.ini", GSdxfxini);
588+
var dir = Path.GetDirectoryName(Properties.Settings.Default.emuDir);
589+
File.Copy(dir + @"\shaders\GSdx.fx", GSdxfx);
590+
File.Copy(dir + @"\shaders\GSdx_FX_Settings.ini", GSdxfxini);
589591
}
590592
}
591593

@@ -766,13 +768,12 @@ private void TitleEditBox_KeyDown(object sender, System.Windows.Input.KeyEventAr
766768
{
767769
List<string> chars = new List<string>();
768770
//Remove unsupported characters
769-
TitleEditBox.Text = TitleEditBox.Text.Replace(@"/", string.Empty);
770-
TitleEditBox.Text = TitleEditBox.Text.Replace(@"\", string.Empty);
771-
TitleEditBox.Text = TitleEditBox.Text.Replace(@":", string.Empty);
772-
TitleEditBox.Text = TitleEditBox.Text.Replace(@"|", string.Empty);
773-
TitleEditBox.Text = TitleEditBox.Text.Replace(@"*", string.Empty);
774-
TitleEditBox.Text = TitleEditBox.Text.Replace(@"<", string.Empty);
775-
TitleEditBox.Text = TitleEditBox.Text.Replace(@">", string.Empty);
771+
{
772+
var tempText = TitleEditBox.Text;
773+
foreach (var illegal in new[] { "/", "\\", ":", "|", "*", "<", ">" })
774+
tempText = tempText.Replace(illegal, string.Empty);
775+
TitleEditBox.Text = tempText;
776+
}
776777

777778
Console.WriteLine(e.Key.ToString());
778779

Spectabis-WPF/Views/Settings.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Diagnostics;
34
using System.IO;
45
using System.Runtime.InteropServices;
@@ -111,7 +112,7 @@ private void Save_Directory(object sender, RoutedEventArgs e)
111112
{
112113
if (Directory.Exists(emudir_text.Text))
113114
{
114-
if (File.Exists(emudir_text.Text + @"/pcsx2.exe"))
115+
if (File.Exists(emudir_text.Text))
115116
{
116117
Properties.Settings.Default.emuDir = emudir_text.Text;
117118
Properties.Settings.Default.Save();
@@ -226,8 +227,9 @@ private void Browse_Click(object sender, RoutedEventArgs e)
226227
//If OK was clicked...
227228
if(BrowserResult == true)
228229
{
229-
if (File.Exists(BrowserDialog.SelectedPath + @"/pcsx2.exe") == false)
230-
{
230+
var filesInFolder = Directory.GetFiles(BrowserDialog.SelectedPath);
231+
232+
if (filesInFolder.Any(p=>p.Contains("pcsx2") && p.EndsWith(".exe")) == false){
231233
//If directory isn't PCSX2's, fall back to beginning
232234
PushSnackbar("Invalid Emulator Directory");
233235
goto ShowDialog;

0 commit comments

Comments
 (0)