Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential fixes for issues #22, #20, and #19 #23

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4e013a8
figured out how to read the registry for steam games saved in either …
mikednjoy Nov 28, 2023
94b2448
figured out how to read the registry for steam gam
mikednjoy Nov 28, 2023
e6499d7
added a way to make the path platform agnostic - fixed some file issues
mikednjoy Nov 29, 2023
ce2d7e8
added functionality to determine OS, then iterate through common inst…
mikednjoy Nov 29, 2023
ae0cb51
Attempted to integrate Registry Search and make it platform agnostic.…
mikednjoy Dec 1, 2023
57d1dd2
Turned the registry search into a function to make future expansion/i…
mikednjoy Dec 1, 2023
84f0d2f
added checking for libraries on linux/macOS - might also turn that in…
mikednjoy Dec 1, 2023
6ebf9ab
no idea how to use this shit
mikednjoy Dec 1, 2023
53c95d0
added sorting by file size to accommodate rockstar (and likely other)…
mikednjoy Dec 1, 2023
831bee5
Delete Registry Test directory
mikednjoy Dec 1, 2023
baf9f5d
Merge pull request #1 from mikednjoy/windows-registry-paths
mikednjoy Dec 1, 2023
2dc6b71
cleaned up files - not sure how they got so fucked. learning git is hard
mikednjoy Dec 1, 2023
0eacf14
fixed merge conflicts
mikednjoy Dec 1, 2023
419307d
implementing fixes from draft push
mikednjoy Dec 2, 2023
ff676aa
Fixed issues brought up in PR - some formatting fixes
mikednjoy Dec 2, 2023
bc14ae4
Fixed issues brought up in PR; hopefully fixed file system, small for…
mikednjoy Dec 2, 2023
b8e98c9
Hopefully actually fixed filesystem now
mikednjoy Dec 2, 2023
514d71c
The PublishProfiles and .pubxml files were in the .gitignore
mikednjoy Dec 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 81 additions & 12 deletions SunshineGameFinder/Program.cs → Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// See https://aka.ms/new-console-template for more information
using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
using Microsoft.Win32;
using Newtonsoft.Json;
using SunshineGameFinder;
using System.CommandLine;
Expand All @@ -11,7 +12,20 @@
const string steamLibraryFolders = @"Program Files (x86)\Steam\steamapps\libraryfolders.vdf";

// default values
var gameDirs = new List<string>() { @"*:\Program Files (x86)\Steam\steamapps\common", @"*:\XboxGames", @"*:\Program Files\EA Games", @"*:\Program Files\Epic Games\", @"*:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\games" };
var gameDirs = new List<string>() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remov these if they're not being used

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used - need to be declared for RegistrySearch method to work

//@"*:\Program Files (x86)\Steam\steamapps\common",
//@"*:\XboxGames", @"*:\Program Files\EA Games",
//@"*:\Program Files\Epic Games\",
//@"*:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\games"
};

var registryDir = new List<string>()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these if they're not being used

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used - need to be declared for ScanFolder method to work, as well as the adding addlDirectories on line 60

{
//@"SOFTWARE\Wow6432Node\Valve\Steam",
//@"SOFTWARE\Valve\Steam"
//Other installer registry paths...
};

var exclusionWords = new List<string>() { "Steam" };
var exeExclusionWords = new List<string>() { "Steam", "Cleanup", "DX", "Uninstall", "Touchup", "redist", "Crash", "Editor" };

Expand Down Expand Up @@ -117,7 +131,10 @@ void ScanFolder(string folder)
Logger.Log($"Skipping {gameName} as it was an excluded word match...");
continue;
}
var exe = Directory.GetFiles(gameDir.FullName, "*.exe", SearchOption.AllDirectories).FirstOrDefault(exefile => {
var exe = Directory.GetFiles(gameDir.FullName, "*.exe", SearchOption.AllDirectories)
.OrderBy(f => new FileInfo(f).Length)
.FirstOrDefault(exefile =>
{
var exeName = new FileInfo(exefile).Name.ToLower();
return exeName == gameName.ToLower() || !exeExclusionWords.Any(ew => exeName.Contains(ew.ToLower()));
});
Expand Down Expand Up @@ -174,23 +191,75 @@ void ScanFolder(string folder)
Console.WriteLine(""); //blank line to separate platforms
}

string MakePathGooder(string path)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename with a more descriptive function name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
string temp = string.Concat("*", $@"{path.AsSpan(1)}") + @"\steamapps\common";
string gooderPath = temp.Replace('/', Path.DirectorySeparatorChar);

return gooderPath;
}

void RegistrySearch()
{
foreach (var path in registryDir)
{
if (path.ToLower().Contains("steam"))
{
RegistryKey? steamRegistry = Registry.LocalMachine.OpenSubKey(path);
if (steamRegistry != null && steamRegistry.GetValue("SteamPath") != null)
{
string temp = steamRegistry.GetValue("SteamPath").ToString();
temp = MakePathGooder(temp);
gameDirs.Add(temp);
}
else
{
steamRegistry = Registry.CurrentUser.OpenSubKey(path);
if (steamRegistry != null && steamRegistry.GetValue("SteamPath") != null)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably dedupe these 2 conditional blocks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
string temp = steamRegistry.GetValue("SteamPath").ToString();
temp = MakePathGooder(temp);
gameDirs.Add(temp);
}
}
}
/*else if (path contains other installer keywords)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused comment blocks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{

}*/
}
}

var logicalDrives = DriveInfo.GetDrives();
var wildcatDriveLetter = new Regex(Regex.Escape(wildcatDrive));

foreach (var drive in logicalDrives)
if (OperatingSystem.IsWindows())
{
var libraryFoldersPath = drive.Name + steamLibraryFolders;
var file = new FileInfo(libraryFoldersPath);
if (!file.Exists)
gameDirs = new List<string>
{
Logger.Log($"libraryfolders.vdf not found on {file.DirectoryName}, skipping...", LogLevel.Warning);
continue;
}
var libraries = VdfConvert.Deserialize(File.ReadAllText(libraryFoldersPath));
foreach(var library in libraries.Value)
@"*:\Program Files (x86)\Steam\steamapps\common",
@"*:\XboxGames",
@"*:\Program Files\EA Games",
@"*:\Program Files\Epic Games\",
@"*:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\games"
//Other common directories
};

bool isSteamLibraryFound = false;
foreach (var drive in logicalDrives)
{
if (library is not VProperty libProp)
var libraryFoldersPath = drive.Name + steamLibraryFolders;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comments explaining how the Vdf stuff works?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments to code - not sure if you meant here or there.

var file = new FileInfo(libraryFoldersPath);
if (!file.Exists)
{
Logger.Log($"libraryfolders.vdf not found on {file.DirectoryName}, skipping...", LogLevel.Warning);
continue;
}
var libraries = VdfConvert.Deserialize(File.ReadAllText(libraryFoldersPath));
foreach (var library in libraries.Value)
{
if (library is not VProperty libProp)
continue;

gameDirs.Add($@"{libProp.Value.Value<string>("path")}\steamapps\common");
}
Expand Down
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move all the files back to where they were originally?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (i think)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep this file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PublishProfiles and .pubxml were in the .gitignore - added back

This file was deleted.