Skip to content

Commit

Permalink
Remove unneeded virtual store files
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Feb 1, 2021
1 parent 604a959 commit 6c83586
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
49 changes: 48 additions & 1 deletion Patches/LaunchAsAdmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
#include <Windows.h>
#include <psapi.h>
#include <string>
#include <shellapi.h>
#include <shlwapi.h>
#pragma warning( suppress : 4091 )
#include <Shlobj.h>
#include <iostream>
#include <fstream>
#include <shellapi.h>
#include "Patches.h"
#include "Common\Utils.h"
#include "Common\LoadModules.h"
#include "Common\Settings.h"
#include "Logging\Logging.h"

Expand Down Expand Up @@ -153,6 +156,50 @@ void CheckAdminAccess()
}
}

void RemoveVirtualStoreFiles()
{
// Get Silent Hill 2 file path
wchar_t sh2path[MAX_PATH];
if (!GetSH2FolderPath(sh2path, MAX_PATH))
{
return;
}

// Remove Silent Hill 2 process name from path
wchar_t *pdest = wcsrchr(sh2path, '\\');
if (pdest)
{
wcscpy_s(pdest, MAX_PATH - wcslen(sh2path), L"\\");
}

// Remove drive root from the path
pdest = wcschr(sh2path, '\\');
if (!pdest || !wcslen(pdest))
{
return;
}

// Get local appdata path
wchar_t vspath[MAX_PATH];
if (FAILED(SHGetFolderPath(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, vspath)))
{
return;
}

// Append virtual store and Silent Hill 2 to local appdata path
if (!PathAppend(vspath, L"VirtualStore\\") || !PathAppend(vspath, pdest))
{
return;
}

// Check if path exists and delete virtual store files in the root
if (PathFileExists(vspath))
{
DeleteAllfiles(vspath);
NeedsRestart = true;
}
}

void RemoveCompatibilityRegistry(HKEY hKeyRoot, const wchar_t *sh2path)
{
// Check Silent Hill 2 file path
Expand Down
1 change: 1 addition & 0 deletions Patches/Patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ DWORD *GetLoadingScreenPointer();
// Function patch declaration
void CheckArgumentsForPID();
void CheckAdminAccess();
void RemoveVirtualStoreFiles();
void RemoveCompatibilityMode();
void SetDelayedStart();
void SetFullscreenImagesRes(DWORD Width, DWORD Height);
Expand Down
2 changes: 1 addition & 1 deletion Resources/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 1858
#define BUILD_NUMBER 1859
3 changes: 2 additions & 1 deletion dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ void DelayedStart()
}
Logging::LogCompatLayer();

// Check for admin access
// Remove unneeded virtual store files and check for admin access
if (CheckForAdminAccess)
{
RemoveVirtualStoreFiles();
CheckAdminAccess();
}

Expand Down

0 comments on commit 6c83586

Please sign in to comment.