Skip to content

Commit

Permalink
ConfigApp/WorkshopInstallHandler: Always cache submission file after …
Browse files Browse the repository at this point in the history
…download

Fixes cached submission files only being written to disk if the user decides to install it after download
  • Loading branch information
pongo1231 committed Feb 12, 2024
1 parent b984cca commit ab185e6
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions ConfigApp/WorkshopInstallHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ string getFileSha256(byte[] buffer)
fileContent = File.ReadAllBytes(targetCacheDirName);
var cachedFileHash = getFileSha256(fileContent);

isFileCached = cachedFileHash == m_SubmissionItem.Sha256;
// Cached files are always compressed
isFileCompressed = true;
if (cachedFileHash == m_SubmissionItem.Sha256)
{
isFileCached = true;
// Cached files are always compressed
isFileCompressed = true;
}
}

if (!isFileCached)
Expand Down Expand Up @@ -151,6 +154,25 @@ string getFileSha256(byte[] buffer)
return;
}

try
{
Directory.CreateDirectory("workshopcache");

// Recompress if necessary for caching
var cachedFileContent = fileContent;
if (!isFileCompressed)
{
var compressor = new Compressor(10);
cachedFileContent = compressor.Wrap(fileContent).ToArray();
}

File.WriteAllBytes(targetCacheDirName, cachedFileContent);
}
catch (Exception)
{
// Doesn't matter if this fails, it's just a cached file anyways
}

var fileStream = new MemoryStream(fileContent);
if (isFileCompressed)
{
Expand Down Expand Up @@ -234,24 +256,6 @@ string getFileSha256(byte[] buffer)
m_SubmissionItem.InstallState = WorkshopSubmissionItem.SubmissionInstallState.Installed;

SystemSounds.Beep.Play();

try
{
Directory.CreateDirectory("workshopcache");

// Recompress if necessary for caching
if (!isFileCompressed)
{
var compressor = new Compressor(10);
fileContent = compressor.Wrap(fileContent).ToArray();
}

File.WriteAllBytes(targetCacheDirName, fileContent);
}
catch (Exception)
{
// Doesn't matter if this fails, it's just a cached file anyways
}
}
catch (HttpRequestException)
{
Expand Down

0 comments on commit ab185e6

Please sign in to comment.