Skip to content

Commit

Permalink
Merge pull request #13 from dotequals/improved-gamelocators
Browse files Browse the repository at this point in the history
Prioritize relative paths for finding TS1
  • Loading branch information
riperiperi authored Nov 23, 2019
2 parents 9449754 + 428da15 commit 85b3db5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
13 changes: 9 additions & 4 deletions Client/Simitone/Simitone.Windows/GameLocator/LinuxLocator.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Simitone.Windows.GameLocator
{
public class LinuxLocator : ILocator
{
public string FindTheSimsOnline()
{
return "game/TSOClient/";
return "";
//string localDir = @"../The Sims Online/TSOClient/";
//if (File.Exists(Path.Combine(localDir, "tuning.dat"))) return localDir;

//return "game/TSOClient/";
}

public string FindTheSims1()
{
string localDir = @"../The Sims/";
if (File.Exists(Path.Combine(localDir, "GameData", "Behavior.iff"))) return localDir;

return "game1/";
}
}
Expand Down
10 changes: 9 additions & 1 deletion Client/Simitone/Simitone.Windows/GameLocator/MacOSLocator.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
using System;
using System.IO;

namespace Simitone.Windows.GameLocator
{
public class MacOSLocator : ILocator
{
public string FindTheSimsOnline()
{
return string.Format("{0}/Documents/The Sims Online/TSOClient/", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
return "";
//string localDir = @"../The Sims Online/TSOClient/";
//if (File.Exists(Path.Combine(localDir, "tuning.dat"))) return localDir;

//return string.Format("{0}/Documents/The Sims Online/TSOClient/", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
}

public string FindTheSims1()
{
string localDir = @"../The Sims/";
if (File.Exists(Path.Combine(localDir, "GameData", "Behavior.iff"))) return localDir;

return "game1/";
}
}
Expand Down
44 changes: 24 additions & 20 deletions Client/Simitone/Simitone.Windows/GameLocator/WindowsLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
Expand All @@ -13,35 +14,37 @@ public class WindowsLocator : ILocator
public string FindTheSimsOnline()
{
return "";
string Software = "";
//string Software = "";

using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{
//Find the path to TSO on the user's system.
RegistryKey softwareKey = hklm.OpenSubKey("SOFTWARE");
//using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
//{
// //Find the path to TSO on the user's system.
// RegistryKey softwareKey = hklm.OpenSubKey("SOFTWARE");

if (Array.Exists(softwareKey.GetSubKeyNames(), delegate (string s) { return s.Equals("Maxis", StringComparison.InvariantCultureIgnoreCase); }))
{
RegistryKey maxisKey = softwareKey.OpenSubKey("Maxis");
if (Array.Exists(maxisKey.GetSubKeyNames(), delegate (string s) { return s.Equals("The Sims Online", StringComparison.InvariantCultureIgnoreCase); }))
{
RegistryKey tsoKey = maxisKey.OpenSubKey("The Sims Online");
string installDir = (string)tsoKey.GetValue("InstallDir");
installDir += "\\TSOClient\\";
return installDir.Replace('\\', '/');
}
}
}
return @"C:\Program Files\Maxis\The Sims Online\TSOClient\".Replace('\\', '/');
// if (Array.Exists(softwareKey.GetSubKeyNames(), delegate (string s) { return s.Equals("Maxis", StringComparison.InvariantCultureIgnoreCase); }))
// {
// RegistryKey maxisKey = softwareKey.OpenSubKey("Maxis");
// if (Array.Exists(maxisKey.GetSubKeyNames(), delegate (string s) { return s.Equals("The Sims Online", StringComparison.InvariantCultureIgnoreCase); }))
// {
// RegistryKey tsoKey = maxisKey.OpenSubKey("The Sims Online");
// string installDir = (string)tsoKey.GetValue("InstallDir");
// installDir += "\\TSOClient\\";
// return installDir.Replace('\\', '/');
// }
// }
//}
//return @"C:\Program Files\Maxis\The Sims Online\TSOClient\".Replace('\\', '/');
}

public string FindTheSims1()
{
string Software = "";
// Search relative directory similar to how macOS and Linux works; allows portability
string localDir = @"../The Sims/";
if (File.Exists(Path.Combine(localDir, "GameData", "Behavior.iff"))) return localDir;

using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{
//Find the path to TSO on the user's system.
//Find the path to TS1 on the user's system.
RegistryKey softwareKey = hklm.OpenSubKey("SOFTWARE");

if (Array.Exists(softwareKey.GetSubKeyNames(), delegate (string s) { return s.Equals("Maxis", StringComparison.InvariantCultureIgnoreCase); }))
Expand All @@ -56,6 +59,7 @@ public string FindTheSims1()
}
}
}
// Fall back to the default install location if the other two checks fail
return @"C:\Program Files (x86)\Maxis\The Sims\".Replace('\\', '/');
}

Expand Down

0 comments on commit 85b3db5

Please sign in to comment.