UI: Extract Google Drive API DLLs only when/if Google Drive Integration is enabled

This commit is contained in:
Sour 2019-01-31 22:26:24 -05:00
parent fac849315f
commit f9b6d07e66
3 changed files with 38 additions and 4 deletions

View file

@ -36,6 +36,14 @@ namespace Mesen.GUI.GoogleDriveIntegration
}
} else {
try {
string googleDriveFolder = Path.Combine(ConfigManager.HomeFolder, "GoogleDrive");
if(!Directory.Exists(googleDriveFolder) || Directory.EnumerateFiles(googleDriveFolder).Where((string filename) => filename.Contains("TokenResponse")).Count() == 0) {
//Sync token has been deleted, disable sync
ConfigManager.Config.PreferenceInfo.CloudSaveIntegration = false;
ConfigManager.ApplyChanges();
return false;
}
InteropEmu.DisplayMessage("GoogleDrive", "SynchronizationStarted");
using(_accessor = new GoogleDriveAccessor()) {
FileDownloadResult result = CloudSyncHelper.DownloadData();

View file

@ -44,6 +44,10 @@ namespace Mesen.GUI
string absoluteFolder = new FileInfo((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath).Directory.FullName;
string targetPath = Path.Combine(ConfigManager.HomeFolder, "GoogleDrive", assemblyFile);
if(ResourceManager.GoogleDlls.Contains(assemblyFile)) {
ResourceManager.ExtractGoogleDriveResources();
}
try {
if(File.Exists(targetPath)) {
return Assembly.LoadFile(targetPath);

View file

@ -100,12 +100,25 @@ namespace Mesen.GUI
} catch { }
}
public static void ExtractGoogleDriveResources()
{
Directory.CreateDirectory(Path.Combine(ConfigManager.HomeFolder, "GoogleDrive"));
ZipArchive zip = new ZipArchive(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mesen.GUI.Dependencies.Dependencies.zip"));
//Extract Google Drive-related DLLs
foreach(ZipArchiveEntry entry in zip.Entries) {
if(ResourceManager.GoogleDlls.Contains(entry.Name)) {
string outputFilename = Path.Combine(ConfigManager.HomeFolder, "GoogleDrive", entry.Name);
ExtractFile(entry, outputFilename);
}
}
}
public static bool ExtractResources()
{
CleanupOldFiles();
Directory.CreateDirectory(Path.Combine(ConfigManager.HomeFolder, "Resources"));
Directory.CreateDirectory(Path.Combine(ConfigManager.HomeFolder, "GoogleDrive"));
ZipArchive zip = new ZipArchive(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mesen.GUI.Dependencies.Dependencies.zip"));
@ -121,9 +134,6 @@ namespace Mesen.GUI
} else if(entry.Name == "MesenUpdater.exe" || entry.Name == "MesenDB.txt") {
string outputFilename = Path.Combine(ConfigManager.HomeFolder, entry.Name);
ExtractFile(entry, outputFilename);
} else if(entry.Name.StartsWith("Google.Apis") || entry.Name == "BouncyCastle.Crypto.dll" || entry.Name == "Zlib.Portable.dll" || entry.Name == "Newtonsoft.Json.dll") {
string outputFilename = Path.Combine(ConfigManager.HomeFolder, "GoogleDrive", entry.Name);
ExtractFile(entry, outputFilename);
} else if(entry.Name == "Font.24.spritefont" || entry.Name == "Font.64.spritefont" || entry.Name == "LICENSE.txt" || entry.Name == "PixelFont.ttf") {
string outputFilename = Path.Combine(ConfigManager.HomeFolder, "Resources", entry.Name);
ExtractFile(entry, outputFilename);
@ -141,5 +151,17 @@ namespace Mesen.GUI
return true;
}
public static HashSet<string> GoogleDlls = new HashSet<string>() {
"BouncyCastle.Crypto.dll",
"Google.Apis.Auth.dll",
"Google.Apis.Auth.PlatformServices.dll",
"Google.Apis.Core.dll",
"Google.Apis.dll",
"Google.Apis.Drive.v3.dll",
"Google.Apis.PlatformServices.dll",
"Newtonsoft.Json.dll",
"Zlib.Portable.dll"
};
}
}