public static bool FromFile(string fileName, out ThemePack result) { var fiSource = new FileInfo(fileName); using (var fs = new FileStream(fiSource.FullName, FileMode.Open, FileAccess.Read)) using (var zf = new ZipFile(fs)) { var ze = zf.GetEntry("info.json"); if (ze == null) { result = null; return(false); } using (var s = zf.GetInputStream(ze)) using (var reader = new StreamReader(s)) { var themePack = JsonConvert.DeserializeObject <ThemePack>(reader.ReadToEnd()); themePack.FileName = fiSource.Name; result = themePack; return(true); } } }
public void Save() { var themePack = new ThemePack { ContainsAudioVisualisation = ContainsAudioVisualisation, ContainsBackground = ContainsBackground, ContainsAppTheme = ContainsAppTheme, ContainsAccentColor = ContainsAccentColor }; var folderToCompress = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "AnyListenThemePack")); if (folderToCompress.Exists) { folderToCompress.Delete(true); } using (var fs = new FileStream(ThemePackPath, FileMode.Create, FileAccess.Write)) using (var zipStream = new ZipOutputStream(fs)) { zipStream.SetLevel(3); if (ContainsAudioVisualisation) { } var jsonFile = new FileInfo(Path.Combine(folderToCompress.FullName, "info.json")); using (var jsonStream = File.Open(jsonFile.FullName, FileMode.CreateNew)) using (var sw = new StreamWriter(jsonStream)) using (var jw = new JsonTextWriter(sw)) { jw.Formatting = Formatting.Indented; var serializer = new JsonSerializer(); serializer.Serialize(jw, this); } var newEntry = new ZipEntry(""); } }