Skip to content

Commit

Permalink
DialogInstall: Use user "temp" directory (if possible) when temporari…
Browse files Browse the repository at this point in the history
…ly extracting plugins to retrieve plugin version
  • Loading branch information
brianferguson committed Jun 24, 2021
1 parent e93ca2a commit d597f30
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
56 changes: 49 additions & 7 deletions Library/DialogInstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,16 +1010,57 @@ void DialogInstall::KeepVariables()

void DialogInstall::ArchivePlugin(const std::wstring& folder, const std::wstring& name)
{
std::wstring path = g_Data.skinsPath + L"@Vault\\Plugins\\";
path += name.substr(0, name.size() - 4) + L'\\'; // Remove extension from folder name
// Extract name without ".dll" extension
size_t pos = name.rfind(L'.');
if (pos == std::wstring::npos) return;

const std::wstring tmpPath = path + L".extracted\\";
const std::wstring plugin = tmpPath + name;
std::wstring finalName = name.substr(0, pos);
if (finalName.empty()) return;

if (ExtractCurrentFile(plugin))
std::wstring finalPath = g_Data.skinsPath + L"@Vault\\Plugins\\";
finalPath += finalName + L'\\';

WCHAR tempFolder[MAX_PATH];
DWORD retVal = GetTempPath(MAX_PATH, tempFolder);
if (retVal > MAX_PATH || retVal == 0)
{
// Could not get user "TEMP" folder, so just use the final path as a temporary folder
wcscpy_s(tempFolder, MAX_PATH, finalPath.c_str());
}
else
{
wcscat_s(tempFolder, MAX_PATH, L"rmskin\\");
}

wcscat_s(tempFolder, MAX_PATH, finalName.c_str());

// Create a random folder
GUID guid;
HRESULT hr = CoCreateGuid(&guid);
if (SUCCEEDED(hr))
{
RPC_WSTR guidStr;
if (RPC_S_OK == UuidToString(&guid, &guidStr))
{
wcscat_s(tempFolder, MAX_PATH, L"_");
wcscat_s(tempFolder, MAX_PATH, (LPCWSTR)guidStr);
RpcStringFree(&guidStr);
}
}

PathAddBackslash(tempFolder);

// Remove folder if it exists (should be rare)
if (_waccess_s(tempFolder, 0) == 0)
{
std::wstring finalPath = path;
System::RemoveFolder(tempFolder);
}

std::wstring plugin = tempFolder;
plugin += name;

if (ExtractCurrentFile(plugin))
{
const std::wstring version = GetFileVersionString(plugin.c_str());
if (!version.empty())
{
Expand All @@ -1028,8 +1069,9 @@ void DialogInstall::ArchivePlugin(const std::wstring& folder, const std::wstring

finalPath += folder + L'\\';
finalPath += name;

System::CopyFiles(plugin, finalPath, true);
System::RemoveFolder(tmpPath);
RemoveDirectory(tempFolder); // Folder should be empty
}
}

Expand Down
2 changes: 1 addition & 1 deletion Library/Library.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<Link>
<AdditionalDependencies>comctl32.lib;dwmapi.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;d3d11.lib;d2d1.lib;dwrite.lib;windowscodecs.lib;Version.lib;Imagehlp.lib;Urlmon.lib;psapi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>comctl32.lib;dwmapi.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;d3d11.lib;d2d1.lib;dwrite.lib;windowscodecs.lib;Version.lib;Imagehlp.lib;Urlmon.lib;psapi.lib;dxguid.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>dwmapi.dll;Iphlpapi.dll;Winmm.dll;Version.dll;Imagehlp.dll;Urlmon.dll;psapi.dll;$(DelayLoadTestDLL)</DelayLoadDLLs>
<ModuleDefinitionFile>Exports.def</ModuleDefinitionFile>
</Link>
Expand Down

0 comments on commit d597f30

Please sign in to comment.