private static void CopyFFmpeg(string destination, bool include32bit, bool include64bit) { if (include32bit) { if (!File.Exists(FFmpeg32bit)) { string filename = SetupHelpers.DownloadFile("https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-4.2-win64-static.zip"); ZipManager.Extract(filename, ".", false, new List <string>() { "ffmpeg.exe" }); File.Move("ffmpeg.exe", FFmpeg32bit); } SetupHelpers.CopyFile(FFmpeg32bit, destination); } if (include64bit) { if (!File.Exists(FFmpeg64bit)) { string filename = SetupHelpers.DownloadFile("https://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-4.2-win32-static.zip"); ZipManager.Extract(filename, ".", false, new List <string>() { "ffmpeg.exe" }); File.Move("ffmpeg.exe", FFmpeg64bit); } SetupHelpers.CopyFile(FFmpeg64bit, destination); } }
public static string ExtractPackage(string packageFilePath, string imageEffectsFolderPath) { if (!string.IsNullOrEmpty(packageFilePath) && File.Exists(packageFilePath) && !string.IsNullOrEmpty(imageEffectsFolderPath)) { string packageName = Path.GetFileNameWithoutExtension(packageFilePath); if (!string.IsNullOrEmpty(packageName) && !packageName.StartsWith(".")) { string destination = Path.Combine(imageEffectsFolderPath, packageName); if (Directory.Exists(destination)) { // TODO: Translate if (MessageBox.Show($"Destination folder already exists:\r\n\"{destination}\"\r\n\r\nWould you like to overwrite it?", "ShareX - " + "Image effect packager", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Directory.Delete(destination, true); } else { return(null); } } ZipManager.Extract(packageFilePath, destination); return(Path.Combine(destination, ConfigFileName)); } } return(null); }
public static string ExtractPackage(string packageFilePath, string destination) { string configJson = null; if (!string.IsNullOrEmpty(packageFilePath) && File.Exists(packageFilePath) && !string.IsNullOrEmpty(destination)) { ZipManager.Extract(packageFilePath, destination, true, entry => { if (FileHelpers.IsImageFile(entry.Name)) { return(true); } if (configJson == null && entry.FullName.Equals(ConfigFileName, StringComparison.OrdinalIgnoreCase)) { using (Stream stream = entry.Open()) using (StreamReader streamReader = new StreamReader(stream, Encoding.UTF8)) { configJson = streamReader.ReadToEnd(); } } return(false); }, 100_000_000); } return(configJson); }
private static void CopyFFmpeg(string destination, bool include32bit, bool include64bit) { if (include32bit) { if (!File.Exists(FFmpeg32bit)) { string filename = SetupHelpers.DownloadFile("https://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-4.3.1-win32-static.zip"); ZipManager.Extract(filename, ".", false, entry => entry.Name.Equals("ffmpeg.exe", StringComparison.OrdinalIgnoreCase), 1_000_000_000); File.Move("ffmpeg.exe", FFmpeg32bit); } SetupHelpers.CopyFile(FFmpeg32bit, destination); } if (include64bit) { if (!File.Exists(FFmpeg64bit)) { string filename = SetupHelpers.DownloadFile("https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-4.3.1-win64-static.zip"); ZipManager.Extract(filename, ".", false, entry => entry.Name.Equals("ffmpeg.exe", StringComparison.OrdinalIgnoreCase), 1_000_000_000); File.Move("ffmpeg.exe", FFmpeg64bit); } SetupHelpers.CopyFile(FFmpeg64bit, destination); } }
/// <summary> /// Partial extract of a single package, before listing the savegames /// Only the quest.ini and translations needs to be extracted to validate quest and get its name /// </summary> /// <param name="path">path of the file to extract</param> public static void ExtractSinglePackagePartial(string path) { // Extract into temp string extractedPath = Path.Combine(ContentData.TempValyriePath, Path.GetFileName(path)); ZipManager.Extract(extractedPath, path, ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_INI_TXT_PIC); }
private static void CopyFFmpeg(string destination, bool include32bit, bool include64bit) { if (include32bit) { if (!File.Exists(FFmpeg32bit)) { string filePath = SetupHelpers.DownloadFile("https://github.com/ShareX/FFmpeg/releases/download/v4.3.1/ffmpeg-4.3.1-win32.zip"); ZipManager.Extract(filePath, ".", false, entry => entry.Name.Equals("ffmpeg.exe", StringComparison.OrdinalIgnoreCase), 100_000_000); File.Move("ffmpeg.exe", FFmpeg32bit); } SetupHelpers.CopyFile(FFmpeg32bit, destination); } if (include64bit) { if (!File.Exists(FFmpeg64bit)) { string filePath = SetupHelpers.DownloadFile("https://github.com/ShareX/FFmpeg/releases/download/v4.3.1/ffmpeg-4.3.1-win64.zip"); ZipManager.Extract(filePath, ".", false, entry => entry.Name.Equals("ffmpeg.exe", StringComparison.OrdinalIgnoreCase), 100_000_000); File.Move("ffmpeg.exe", FFmpeg64bit); } SetupHelpers.CopyFile(FFmpeg64bit, destination); } }
/// <summary> /// Fully extract one single package, before starting a quest, and save package filename /// </summary> /// <param name="path">path of the file to extract</param> public static void ExtractSinglePackageFull(string path) { // Extract into temp string tempValkyriePath = ContentData.TempValyriePath; mkDir(tempValkyriePath); string extractedPath = Path.Combine(tempValkyriePath, Path.GetFileName(path)); ZipManager.Extract(extractedPath, path, ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_FULL); }
/// <summary> /// Partial extract of all package in a directory, to list quests, and save package filename /// </summary> /// <param name="path">path of the directory containing .valkyrie package</param> public static void ExtractPackages(string path) { // Find all packages at path string[] archives = Directory.GetFiles(path, "*.valkyrie", SearchOption.AllDirectories); // Extract all packages foreach (string f in archives) { string extractedPath = Path.Combine(ContentData.TempValyriePath, Path.GetFileName(f)); ZipManager.Extract(extractedPath, f, ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_INI_TXT_PIC); } }
public static bool ExtractFFmpeg(string archivePath, string extractPath) { try { ZipManager.Extract(archivePath, extractPath, false, entry => entry.Name.Equals("ffmpeg.exe", StringComparison.OrdinalIgnoreCase), 1_000_000_000); return(true); } catch (Exception e) { DebugHelper.WriteException(e); } return(false); }
public static bool ExtractFFmpeg(string archivePath, string extractPath) { try { ZipManager.Extract(archivePath, extractPath, false, new List <string>() { "ffmpeg.exe" }); return(true); } catch (Exception e) { DebugHelper.WriteException(e); } return(false); }
public static string ExtractPackage(string packageFilePath, string destination) { if (!string.IsNullOrEmpty(packageFilePath) && File.Exists(packageFilePath) && !string.IsNullOrEmpty(destination)) { string configFilePath = Path.Combine(destination, ConfigFileName); if (File.Exists(configFilePath)) { File.Delete(configFilePath); } ZipManager.Extract(packageFilePath, destination); return(configFilePath); } return(null); }
public SaveData(int num = 0) { Game game = Game.Get(); if (!File.Exists(SaveFile(num))) { return; } try { if (!Directory.Exists(ContentData.TempValyriePath)) { Directory.CreateDirectory(ContentData.TempValyriePath); } string valkyrieLoadPath = Path.Combine(ContentData.TempValyriePath, "Preload"); if (!Directory.Exists(valkyrieLoadPath)) { Directory.CreateDirectory(valkyrieLoadPath); } ZipManager.Extract(valkyrieLoadPath, SaveFile(num), ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_SAVE_INI_PIC); image = ContentData.FileToTexture(Path.Combine(valkyrieLoadPath, "image.png")); string data = File.ReadAllText(Path.Combine(valkyrieLoadPath, "save.ini")); IniData saveData = IniRead.ReadFromString(data); // when loading a quest, path should always be $TMP/load/quest/$subquest/quest.ini // Make sure it is when loading a quest saved for the first time, as in that case it is the original load path string questLoadPath = Path.GetDirectoryName(saveData.Get("Quest", "path")); string questOriginalPath = saveData.Get("Quest", "originalpath"); // loading a quest saved for the first time if (questLoadPath.Contains(questOriginalPath)) { questLoadPath = questLoadPath.Replace(questOriginalPath, ContentData.ValkyrieLoadQuestPath); } // use preload path rather than load questLoadPath = questLoadPath.Replace(ContentData.ValkyrieLoadPath, ContentData.ValkyriePreloadPath); QuestData.Quest q = new QuestData.Quest(questLoadPath); if (!q.valid) { ValkyrieDebug.Log("Warning: Save " + num + " contains unsupported quest version." + Environment.NewLine); return; } quest_name = saveData.Get("Quest", "questname"); if (VersionManager.VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from a future version." + Environment.NewLine); return; } if (!VersionManager.VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from an old unsupported version." + Environment.NewLine); return; } saveTime = DateTime.Parse(saveData.Get("Quest", "time")); valid = true; } catch (Exception e) { ValkyrieDebug.Log("Warning: Unable to open save file: " + SaveFile(num) + "\nException: " + e.ToString()); } }
// Load a saved game, does nothing if file does not exist public static void Load(int num = 0) { Game game = Game.Get(); try { if (File.Exists(SaveFile(num))) { if (!Directory.Exists(ContentData.TempValyriePath)) { Directory.CreateDirectory(ContentData.TempValyriePath); } string valkyrieLoadPath = Path.Combine(ContentData.TempValyriePath, "Load"); if (!Directory.Exists(valkyrieLoadPath)) { Directory.CreateDirectory(valkyrieLoadPath); } Directory.Delete(valkyrieLoadPath, true); ZipManager.Extract(valkyrieLoadPath, SaveFile(num), ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_FULL); string savefile_content = File.ReadAllText(Path.Combine(valkyrieLoadPath, "save.ini")); IniData saveData = IniRead.ReadFromString(savefile_content); // when loading a quest, path should always be $TMP/load/quest/$subquest/quest.ini // Make sure it is when loading a quest saved for the first time, as in that case it is the original load path string questLoadPath = Path.GetDirectoryName(saveData.Get("Quest", "path")); string questOriginalPath = saveData.Get("Quest", "originalpath"); // loading a quest saved for the first time if (questLoadPath.Contains(questOriginalPath)) { questLoadPath = questLoadPath.Replace(questOriginalPath, ContentData.ValkyrieLoadQuestPath); } // Check that quest in save is valid QuestData.Quest q = new QuestData.Quest(questLoadPath); if (!q.valid) { ValkyrieDebug.Log("Error: save contains unsupported quest version." + Environment.NewLine); GameStateManager.MainMenu(); return; } saveData.data["Quest"]["path"] = Path.Combine(questLoadPath, "quest.ini"); if (VersionManager.VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from a future version." + Environment.NewLine); GameStateManager.MainMenu(); return; } if (!VersionManager.VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from an old unsupported version." + Environment.NewLine); GameStateManager.MainMenu(); return; } Destroyer.Dialog(); // Load content that the save game uses Dictionary <string, string> packs = saveData.Get("Packs"); foreach (KeyValuePair <string, string> kv in packs) { // Support for save games from 1.2 and older if (kv.Key.Equals("FA")) { game.ContentLoader.LoadContentID("FAI"); game.ContentLoader.LoadContentID("FAM"); game.ContentLoader.LoadContentID("FAT"); } if (kv.Key.Equals("CotW")) { game.ContentLoader.LoadContentID("CotWI"); game.ContentLoader.LoadContentID("CotWM"); game.ContentLoader.LoadContentID("CotWT"); } if (kv.Key.Equals("MoM1E")) { game.ContentLoader.LoadContentID("MoM1EI"); game.ContentLoader.LoadContentID("MoM1EM"); game.ContentLoader.LoadContentID("MoM1ET"); } else { game.ContentLoader.LoadContentID(kv.Key); } } // This loads the game new Quest(saveData); // Draw things on the screen game.heroCanvas.SetupUI(); game.heroCanvas.UpdateImages(); game.heroCanvas.UpdateStatus(); if (game.gameType.DisplayMorale()) { game.moraleDisplay = new MoraleDisplay(); } if (!game.gameType.DisplayHeroes()) { game.heroCanvas.Clean(); } // Create the menu button new MenuButton(); new LogButton(); new SkillButton(); new InventoryButton(); game.stageUI = new NextStageButton(); } } catch (IOException e) { ValkyrieDebug.Log("Error: Unable to open save file: " + SaveFile(num) + " " + e.Message); Application.Quit(); } }
private static void ExtractFiles(string zipToExtractPath, DirectoryInfo extractionDestinationPath, ZipExtraction zipExtractionMode) { var zipFiles = ZipManager.Extract(new MemoryStream(File.ReadAllBytes(zipToExtractPath))); foreach (var zipItem in zipFiles.Where(zipItem => zipItem.Data.Length > 0)) { var names = zipItem.Filename.Split('/'); // Carico l'effettivo nome file var fileName = names.Length > 0 ? names.Last() : names[0]; var destinationName = Path.Combine(extractionDestinationPath.FullName, fileName); // Definisco come gestire il nesting switch (zipExtractionMode) { // Estrazione piatta di tutti gli elementi case ZipExtraction.FlatExtraction: { // Niente da fare: in fileName ho già il nome e non serve caricare le cartelle } break; case ZipExtraction.FullDirectoryExtraction: { // Devo caricare tutte le directory (se presenti) if (names.Length > 1) { var fileInfo = new FileInfo(Path.Combine(extractionDestinationPath.FullName, zipItem.Filename.Replace('/', '\\'))); if (fileInfo.Directory != null) { // Creo la directory se non esiste fileInfo.Directory.Create(); // Aggiorno il path destinationName = Path.Combine(destinationName, fileInfo.Directory.FullName, fileName); } } } break; case ZipExtraction.FullInternalDirectionExtraction: { // Carico tutte le directory meno che la prima // Devo caricare tutte le directory (se presenti) if (names.Length > 2) { var fileInfo = new FileInfo(Path.Combine(extractionDestinationPath.FullName, zipItem.Filename.Substring(zipItem.Filename.IndexOf('/') + 1).Replace('/', '\\'))); if (fileInfo.Directory != null) { // Creo la directory se non esiste fileInfo.Directory.Create(); // Aggiorno il path destinationName = Path.Combine(destinationName, fileInfo.Directory.FullName, fileName); } } } break; } File.WriteAllBytes(destinationName, zipItem.Data); } // Elimino lo zip di aggiornamento File.Delete(zipToExtractPath); }