public static void Zip(string sourceDirectory, string destinationPath) { if (sourceDirectory == null) { Debug.LogError("Null source directory string, cannot zip!"); } if (!Directory.Exists(sourceDirectory)) { Debug.LogError("Directory does not exist, cannot zip!"); } if (destinationPath == null) { Debug.LogError("Null destination path string, cannot zip!"); } if (File.Exists(destinationPath)) { File.Delete(destinationPath); } GameIO.EnsureDirectory(GameIO.DirectoryFromFile(destinationPath)); ZipFile.CreateFromDirectory(sourceDirectory, destinationPath, CompressionLevel.Optimal, false); Debug.Log("Zipped '{0}' to '{1}'.".Form(sourceDirectory, destinationPath)); }
public static void UnZip(string zipPath, string destinationDir, bool deleteExistingDir = true) { if (string.IsNullOrWhiteSpace(zipPath)) { Debug.LogError("Null or blank zip file path! Cannot unzip!"); return; } if (string.IsNullOrWhiteSpace(destinationDir)) { Debug.LogError("Null or blank destination directory path! Cannot unzip!"); return; } if (!File.Exists(zipPath)) { Debug.LogError("Did not find zip file at '{0}', cannot unzip!".Form(zipPath)); return; } if (Directory.Exists(destinationDir)) { // Delete it? if (deleteExistingDir) { Directory.Delete(destinationDir, true); } } GameIO.EnsureDirectory(destinationDir); ZipFile.ExtractToDirectory(zipPath, destinationDir); }
public void Save(bool useTemp, bool deleteTemp = true) { if (Data == null) { Debug.LogError("Tile Map Data is null, cannot save! Invalid loaded map!"); return; } // Should be in editor mode for this to work correctly, but it theoretically also works even at runtime. string zipFilePath = Data.SavedZipPath; Debug.Log("Saving map '{0}' to {1}".Form(this, zipFilePath)); string fileSaveDir = null; if (useTemp) { // Save to a temporary folder. fileSaveDir = Path.Combine(Path.GetTempPath(), Data.InternalName); } else { // Save to the extracted (unzipped) folder, and then zip it up anyway. fileSaveDir = Path.Combine(GameIO.UnzippedMapsDirectory, Data.InternalName); } // Save all map data to file. Debug.Log("Saving files to '{0}' ({1}) ...".Form(fileSaveDir, useTemp ? "temp" : "pers")); GameIO.EnsureDirectory(fileSaveDir); var fs = MapIO.StartWrite(Path.Combine(fileSaveDir, TILE_DATA_FILE)); MapIO.WriteTileIDs(fs, TileIDs); MapIO.End(fs); // Save metadata. GameIO.ObjectToFile(this.Data, Path.Combine(fileSaveDir, METADATA_FILE)); // Work out all the tile varieties. // TODO fs = MapIO.StartWrite(Path.Combine(fileSaveDir, TILE_VARIATION_FILE)); MapIO.WriteTileVariations(fs, this.TileVariations); MapIO.End(fs); // Grab all the saved files, and zip the up into the save zip path. MapIO.Zip(fileSaveDir, zipFilePath); // Delete the temporary directory, just to be clean. if (useTemp && deleteTemp) { Directory.Delete(fileSaveDir, true); } Debug.Log("Finished saving, zipped to '{0}'".Form(zipFilePath)); }