public static bool UpdateEntry(string zipFileName, string entryname, byte[] buffer, string password = null) { try { string dir = Path.GetDirectoryName(zipFileName); string tmpfile = Path.Combine(dir, entryname + ".tmp"); if (File.Exists(tmpfile)) { File.Delete(tmpfile); } FileStream streamWriter = File.Create(tmpfile); streamWriter.Write(buffer, 0, buffer.Length); SharpZipLib.Zip.ZipFile s = new SharpZipLib.Zip.ZipFile(zipFileName); s.Password = password; SharpZipLib.Zip.StaticDiskDataSource data = new SharpZipLib.Zip.StaticDiskDataSource(tmpfile); s.BeginUpdate(); s.Add(data, entryname); s.CommitUpdate(); s.Close(); streamWriter.Close(); if (File.Exists(tmpfile)) { File.Delete(tmpfile); } return(true); } catch (Exception e) { LogUtil.LogError(e.Message); return(false); } }
/// <summary> /// 根据所选文件打包下载 /// 编写日期:2018/2/22 /// 编写人:郑亚波 /// </summary> /// <param name="response"></param> /// <param name="files"></param> /// <param name="zipFileName"></param> public void Download(System.Web.HttpResponse response, IEnumerable <string> files, string zipFileName) { //根据所选文件打包下载 System.IO.MemoryStream ms = new System.IO.MemoryStream(); byte[] buffer = null; using (ICSharpCode.SharpZipLib.Zip.ZipFile file = ICSharpCode.SharpZipLib.Zip.ZipFile.Create(ms)) { file.BeginUpdate(); file.NameTransform = new MyNameTransfom();//通过这个名称格式化器,可以将里面的文件名进行一些处理。默认情况下,会自动根据文件的路径在zip中创建有关的文件夹。 foreach (var item in files) { if (System.IO.File.Exists(item.ToString())) { file.Add(item); } } file.CommitUpdate(); buffer = new byte[ms.Length]; ms.Position = 0; ms.Read(buffer, 0, buffer.Length); } response.AddHeader("content-disposition", "attachment;filename=" + zipFileName); response.BinaryWrite(buffer); response.Flush(); response.End(); }
internal static void ZipTempMapFiles(string strDestMapNameAndPath) { ICSharpCode.SharpZipLib.Zip.ZipFile NewMapZipped = ICSharpCode.SharpZipLib.Zip.ZipFile.Create(strDestMapNameAndPath); NewMapZipped.BeginUpdate(); ZipFilesInDir(new DirectoryInfo(MAPS_INITIAL_DIR), NewMapZipped); //NewMapZipped.Add(@"Maps\Multiplayer\"+"\\"+); //NewMapZipped.Add(@"Maps\Multiplayer\TestMap\GroundTerrain.bin"); NewMapZipped.CommitUpdate(); NewMapZipped.Close(); }
public static bool UpdateEntry(string zipFileName, string entryname, string filename, string password = null) { try { SharpZipLib.Zip.ZipFile s = new SharpZipLib.Zip.ZipFile(zipFileName); s.Password = password; SharpZipLib.Zip.StaticDiskDataSource data = new SharpZipLib.Zip.StaticDiskDataSource(filename); s.BeginUpdate(); s.Add(data, entryname); s.CommitUpdate(); s.Close(); return(true); } catch (Exception e) { LogUtil.LogError(e.Message); return(false); } }
public bool CreateLegacyGoPackage(string sourceArchive, string sourceDirectory) { try { var zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(sourceArchive); zipFile.BeginUpdate(); foreach (var file in Directory.EnumerateFiles( sourceDirectory, "*.*", searchOption: SearchOption.TopDirectoryOnly)) { var fileInfo = new FileInfo(file); Log.Info($"Adding File: {fileInfo.Name} to Package"); zipFile.Add(fileInfo.FullName, fileInfo.Name); Log.Info($"Successfully Added File: {fileInfo.Name} to Package"); } Log.Info("Updating Package entries this may take time dependent on package size."); zipFile.CommitUpdate(); zipFile.Close(); Log.Info("Packaging Successfully completed."); return(true); } catch (Exception createGoEx) { Log.Error($"Failed to Packaging Legacy Go deliverable: {sourceArchive} - {createGoEx.Message}"); if (createGoEx.InnerException != null) { Log.Error($"Inner Exception: {createGoEx.InnerException.Message}"); } return(false); } }
public static bool DeleteEntry(string zipFileName, string entryname, string password = null) { try { SharpZipLib.Zip.ZipFile s = new SharpZipLib.Zip.ZipFile(zipFileName); s.Password = password; SharpZipLib.Zip.ZipEntry entry = s.GetEntry(entryname); if (null == entry) { s.Close(); return(true); } s.BeginUpdate(); s.Delete(entry); s.CommitUpdate(); s.Close(); return(true); } catch (Exception e) { LogUtil.LogError(e.Message); return(false); } }
private void btnExport_Click(object sender, EventArgs e) { //acquire target var sfd = new SaveFileDialog(); sfd.Filter = "XRNS (*.xrns)|*.xrns"; if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; //configuration: var outPath = sfd.FileName; string templatePath = Path.Combine(Path.GetDirectoryName(outPath), "template.xrns"); int configuredPatternLength = int.Parse(txtPatternLength.Text); //load template MemoryStream msSongXml = new MemoryStream(); var zfTemplate = new ICSharpCode.SharpZipLib.Zip.ZipFile(templatePath); { int zfSongXmlIndex = zfTemplate.FindEntry("Song.xml", true); using (var zis = zfTemplate.GetInputStream(zfTemplate.GetEntry("Song.xml"))) { byte[] buffer = new byte[4096]; // 4K is optimum ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(zis, msSongXml, buffer); } } XElement templateRoot = XElement.Parse(System.Text.Encoding.UTF8.GetString(msSongXml.ToArray())); //get the pattern pool, and whack the child nodes var xPatterns = templateRoot.XPathSelectElement("//Patterns"); var xPatternPool = xPatterns.Parent; xPatterns.Remove(); var writer = new StringWriter(); writer.WriteLine("<Patterns>"); int pulse0_lastNote = -1; int pulse0_lastType = -1; int pulse1_lastNote = -1; int pulse1_lastType = -1; int tri_lastNote = -1; int noise_lastNote = -1; int patternCount = 0; int time = 0; while (time < Log.Count) { patternCount++; //begin writing pattern: open the tracks list writer.WriteLine("<Pattern>"); writer.WriteLine("<NumberOfLines>{0}</NumberOfLines>", configuredPatternLength); writer.WriteLine("<Tracks>"); //write the pulse tracks for (int TRACK = 0; TRACK < 2; TRACK++) { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); int lastNote = TRACK == 0 ? pulse0_lastNote : pulse1_lastNote; int lastType = TRACK == 0 ? pulse0_lastType : pulse1_lastType; for (int i = 0; i < configuredPatternLength; i++) { int patLine = i; int index = i + time; if (index >= Log.Count) continue; var rec = Log[index]; PulseState pulse = new PulseState(); if (TRACK == 0) pulse = rec.pulse0; if (TRACK == 1) pulse = rec.pulse1; //transform quieted notes to dead notes //blech its buggy, im tired //if (pulse.vol == 0) // pulse.en = false; bool keyoff = false, keyon = false; if (lastNote != -1 && !pulse.en) { lastNote = -1; lastType = -1; keyoff = true; } else if (lastNote != pulse.note && pulse.en) keyon = true; if (lastType != pulse.type && pulse.note != -1) keyon = true; if (pulse.en) { lastNote = pulse.note; lastType = pulse.type; } writer.WriteLine("<Line index=\"{0}\">", patLine); writer.WriteLine("<NoteColumns>"); writer.WriteLine("<NoteColumn>"); if (keyon) { writer.WriteLine("<Note>{0}</Note>", NameForNote(pulse.note)); writer.WriteLine("<Instrument>{0:X2}</Instrument>", pulse.type); } else if (keyoff) writer.WriteLine("<Note>OFF</Note>"); if(lastNote != -1) writer.WriteLine("<Volume>{0:X2}</Volume>", pulse.vol * 8); writer.WriteLine("</NoteColumn>"); writer.WriteLine("</NoteColumns>"); writer.WriteLine("</Line>"); } //close PatternTrack writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); if (TRACK == 0) { pulse0_lastNote = lastNote; pulse0_lastType = lastType; } else { pulse1_lastNote = lastNote; pulse1_lastType = lastType; } } //pulse tracks loop //triangle track generation { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); for (int i = 0; i < configuredPatternLength; i++) { int patLine = i; int index = i + time; if (index >= Log.Count) continue; var rec = Log[index]; TriangleState tri = rec.triangle; { bool keyoff = false, keyon = false; if (tri_lastNote != -1 && !tri.en) { tri_lastNote = -1; keyoff = true; } else if (tri_lastNote != tri.note && tri.en) keyon = true; if(tri.en) tri_lastNote = tri.note; writer.WriteLine("<Line index=\"{0}\">", patLine); writer.WriteLine("<NoteColumns>"); writer.WriteLine("<NoteColumn>"); if (keyon) { writer.WriteLine("<Note>{0}</Note>", NameForNote(tri.note)); writer.WriteLine("<Instrument>08</Instrument>"); } else if (keyoff) writer.WriteLine("<Note>OFF</Note>"); //no need for tons of these //if(keyon) writer.WriteLine("<Volume>80</Volume>"); writer.WriteLine("</NoteColumn>"); writer.WriteLine("</NoteColumns>"); writer.WriteLine("</Line>"); } } //close PatternTrack writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); } //noise track generation { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); for (int i = 0; i < configuredPatternLength; i++) { int patLine = i; int index = i + time; if (index >= Log.Count) continue; var rec = Log[index]; NoiseState noise = rec.noise; //transform quieted notes to dead notes //blech its buggy, im tired //if (noise.vol == 0) // noise.en = false; { bool keyoff = false, keyon = false; if (noise_lastNote != -1 && !noise.en) { noise_lastNote = -1; keyoff = true; } else if (noise_lastNote != noise.note && noise.en) keyon = true; if (noise.en) noise_lastNote = noise.note; writer.WriteLine("<Line index=\"{0}\">", patLine); writer.WriteLine("<NoteColumns>"); writer.WriteLine("<NoteColumn>"); if (keyon) { writer.WriteLine("<Note>{0}</Note>", NameForNote(noise.note)); writer.WriteLine("<Instrument>04</Instrument>"); } else if (keyoff) writer.WriteLine("<Note>OFF</Note>"); if (noise_lastNote != -1) writer.WriteLine("<Volume>{0:X2}</Volume>", noise.vol * 8); writer.WriteLine("</NoteColumn>"); writer.WriteLine("</NoteColumns>"); writer.WriteLine("</Line>"); } } //close PatternTrack writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); } //noise track generation //write empty track for now for pcm for (int TRACK = 4; TRACK < 5; TRACK++) { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); } //we definitely need a dummy master track now writer.WriteLine("<PatternMasterTrack type=\"PatternMasterTrack\">"); writer.WriteLine("</PatternMasterTrack>"); //close tracks writer.WriteLine("</Tracks>"); //close pattern writer.WriteLine("</Pattern>"); time += configuredPatternLength; } //main pattern loop writer.WriteLine("</Patterns>"); writer.Flush(); var xNewPatternList = XElement.Parse(writer.ToString()); xPatternPool.Add(xNewPatternList); //write pattern sequence writer = new StringWriter(); writer.WriteLine("<SequenceEntries>"); for (int i = 0; i < patternCount; i++) { writer.WriteLine("<SequenceEntry>"); writer.WriteLine("<IsSectionStart>false</IsSectionStart>"); writer.WriteLine("<Pattern>{0}</Pattern>", i); writer.WriteLine("</SequenceEntry>"); } writer.WriteLine("</SequenceEntries>"); var xPatternSequence = templateRoot.XPathSelectElement("//PatternSequence"); xPatternSequence.XPathSelectElement("SequenceEntries").Remove(); xPatternSequence.Add(XElement.Parse(writer.ToString())); //copy template file to target File.Delete(outPath); File.Copy(templatePath, outPath); var msOutXml = new MemoryStream(); templateRoot.Save(msOutXml); msOutXml.Flush(); msOutXml.Position = 0; var zfOutput = new ICSharpCode.SharpZipLib.Zip.ZipFile(outPath); zfOutput.BeginUpdate(); zfOutput.Add(new Stupid { stream = msOutXml }, "Song.xml"); zfOutput.CommitUpdate(); zfOutput.Close(); //for easier debugging, write patterndata XML //DUMP_TO_DISK(msOutXml.ToArray()) }
public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool b = false; componentEvents.FireInformation(1, "UnZip SSIS", "Start 1", null, 0, ref b); componentEvents.FireInformation(1, "UnZip SSIS", "Start process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b); if (_typeOperation == Type_Operation.Please_Select) { componentEvents.FireError(1, "UnZip SSIS", "Please select type operation (De/Compress).", null, 0); throw new Exception("Please select type operation (De/Compress)."); } ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip(); if (!_folderSource.EndsWith("\\")) { _folderSource = _folderSource + "\\"; } if (!_folderDest.EndsWith("\\")) { _folderDest = _folderDest + "\\"; } if (!string.IsNullOrEmpty(_password)) { fz.Password = _password; } try { if (!System.IO.Directory.Exists(_folderDest)) { componentEvents.FireInformation(1, "UnZip SSIS", "Create Folder: '" + _folderDest + "'.", null, 0, ref b); System.IO.Directory.CreateDirectory(_folderDest); } if (_typeOperation == Type_Operation.Compress) { fz.CreateZip(_folderDest + _fileZip, _folderSource, _Recurse, _FileFilter); if ((_testarchive) || (!string.IsNullOrEmpty(_comment))) { ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(_folderDest + _fileZip); if (_testarchive) { componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _fileZip + ")", null, 0, ref b); if (!zipFile.TestArchive(true)) { throw new Exception("Verify file zip: " + _fileZip + " failed."); } } if (!string.IsNullOrEmpty(_comment)) { componentEvents.FireInformation(1, "UnZip SSIS", "Set Comment.", null, 0, ref b); zipFile.BeginUpdate(); zipFile.SetComment(_comment); zipFile.CommitUpdate(); } } } else { if (_testarchive) { ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(_folderSource + _fileZip); componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _fileZip + ")", null, 0, ref b); if (!zipFile.TestArchive(true)) { throw new Exception("Verify file zip: " + _fileZip + " failed."); } } fz.ExtractZip(_folderSource + _fileZip, _folderDest, _FileFilter); } } catch (Exception ex) { throw; } componentEvents.FireInformation(1, "UnZip SSIS", "End process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b); return(DTSExecResult.Success); }
private void btnExport_Click(object sender, EventArgs e) { //acquire target var sfd = new SaveFileDialog(); sfd.Filter = "XRNS (*.xrns)|*.xrns"; if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } //configuration: var outPath = sfd.FileName; string templatePath = Path.Combine(Path.GetDirectoryName(outPath), "template.xrns"); int configuredPatternLength = int.Parse(txtPatternLength.Text); //load template MemoryStream msSongXml = new MemoryStream(); var zfTemplate = new ICSharpCode.SharpZipLib.Zip.ZipFile(templatePath); { int zfSongXmlIndex = zfTemplate.FindEntry("Song.xml", true); using (var zis = zfTemplate.GetInputStream(zfTemplate.GetEntry("Song.xml"))) { byte[] buffer = new byte[4096]; // 4K is optimum ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(zis, msSongXml, buffer); } } XElement templateRoot = XElement.Parse(System.Text.Encoding.UTF8.GetString(msSongXml.ToArray())); //get the pattern pool, and whack the child nodes var xPatterns = templateRoot.XPathSelectElement("//Patterns"); var xPatternPool = xPatterns.Parent; xPatterns.Remove(); var writer = new StringWriter(); writer.WriteLine("<Patterns>"); int pulse0_lastNote = -1; int pulse0_lastType = -1; int pulse1_lastNote = -1; int pulse1_lastType = -1; int tri_lastNote = -1; int noise_lastNote = -1; int patternCount = 0; int time = 0; while (time < Log.Count) { patternCount++; //begin writing pattern: open the tracks list writer.WriteLine("<Pattern>"); writer.WriteLine("<NumberOfLines>{0}</NumberOfLines>", configuredPatternLength); writer.WriteLine("<Tracks>"); //write the pulse tracks for (int TRACK = 0; TRACK < 2; TRACK++) { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); int lastNote = TRACK == 0 ? pulse0_lastNote : pulse1_lastNote; int lastType = TRACK == 0 ? pulse0_lastType : pulse1_lastType; for (int i = 0; i < configuredPatternLength; i++) { int patLine = i; int index = i + time; if (index >= Log.Count) { continue; } var rec = Log[index]; PulseState pulse = new PulseState(); if (TRACK == 0) { pulse = rec.pulse0; } if (TRACK == 1) { pulse = rec.pulse1; } //transform quieted notes to dead notes //blech its buggy, im tired //if (pulse.vol == 0) // pulse.en = false; bool keyoff = false, keyon = false; if (lastNote != -1 && !pulse.en) { lastNote = -1; lastType = -1; keyoff = true; } else if (lastNote != pulse.note && pulse.en) { keyon = true; } if (lastType != pulse.type && pulse.note != -1) { keyon = true; } if (pulse.en) { lastNote = pulse.note; lastType = pulse.type; } writer.WriteLine("<Line index=\"{0}\">", patLine); writer.WriteLine("<NoteColumns>"); writer.WriteLine("<NoteColumn>"); if (keyon) { writer.WriteLine("<Note>{0}</Note>", NameForNote(pulse.note)); writer.WriteLine("<Instrument>{0:X2}</Instrument>", pulse.type); } else if (keyoff) { writer.WriteLine("<Note>OFF</Note>"); } if (lastNote != -1) { writer.WriteLine("<Volume>{0:X2}</Volume>", pulse.vol * 8); } writer.WriteLine("</NoteColumn>"); writer.WriteLine("</NoteColumns>"); writer.WriteLine("</Line>"); } //close PatternTrack writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); if (TRACK == 0) { pulse0_lastNote = lastNote; pulse0_lastType = lastType; } else { pulse1_lastNote = lastNote; pulse1_lastType = lastType; } } //pulse tracks loop //triangle track generation { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); for (int i = 0; i < configuredPatternLength; i++) { int patLine = i; int index = i + time; if (index >= Log.Count) { continue; } var rec = Log[index]; TriangleState tri = rec.triangle; { bool keyoff = false, keyon = false; if (tri_lastNote != -1 && !tri.en) { tri_lastNote = -1; keyoff = true; } else if (tri_lastNote != tri.note && tri.en) { keyon = true; } if (tri.en) { tri_lastNote = tri.note; } writer.WriteLine("<Line index=\"{0}\">", patLine); writer.WriteLine("<NoteColumns>"); writer.WriteLine("<NoteColumn>"); if (keyon) { writer.WriteLine("<Note>{0}</Note>", NameForNote(tri.note)); writer.WriteLine("<Instrument>08</Instrument>"); } else if (keyoff) { writer.WriteLine("<Note>OFF</Note>"); } //no need for tons of these //if(keyon) writer.WriteLine("<Volume>80</Volume>"); writer.WriteLine("</NoteColumn>"); writer.WriteLine("</NoteColumns>"); writer.WriteLine("</Line>"); } } //close PatternTrack writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); } //noise track generation { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); for (int i = 0; i < configuredPatternLength; i++) { int patLine = i; int index = i + time; if (index >= Log.Count) { continue; } var rec = Log[index]; NoiseState noise = rec.noise; //transform quieted notes to dead notes //blech its buggy, im tired //if (noise.vol == 0) // noise.en = false; { bool keyoff = false, keyon = false; if (noise_lastNote != -1 && !noise.en) { noise_lastNote = -1; keyoff = true; } else if (noise_lastNote != noise.note && noise.en) { keyon = true; } if (noise.en) { noise_lastNote = noise.note; } writer.WriteLine("<Line index=\"{0}\">", patLine); writer.WriteLine("<NoteColumns>"); writer.WriteLine("<NoteColumn>"); if (keyon) { writer.WriteLine("<Note>{0}</Note>", NameForNote(noise.note)); writer.WriteLine("<Instrument>04</Instrument>"); } else if (keyoff) { writer.WriteLine("<Note>OFF</Note>"); } if (noise_lastNote != -1) { writer.WriteLine("<Volume>{0:X2}</Volume>", noise.vol * 8); } writer.WriteLine("</NoteColumn>"); writer.WriteLine("</NoteColumns>"); writer.WriteLine("</Line>"); } } //close PatternTrack writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); } //noise track generation //write empty track for now for pcm for (int TRACK = 4; TRACK < 5; TRACK++) { writer.WriteLine("<PatternTrack type=\"PatternTrack\">"); writer.WriteLine("<Lines>"); writer.WriteLine("</Lines>"); writer.WriteLine("</PatternTrack>"); } //we definitely need a dummy master track now writer.WriteLine("<PatternMasterTrack type=\"PatternMasterTrack\">"); writer.WriteLine("</PatternMasterTrack>"); //close tracks writer.WriteLine("</Tracks>"); //close pattern writer.WriteLine("</Pattern>"); time += configuredPatternLength; } //main pattern loop writer.WriteLine("</Patterns>"); writer.Flush(); var xNewPatternList = XElement.Parse(writer.ToString()); xPatternPool.Add(xNewPatternList); //write pattern sequence writer = new StringWriter(); writer.WriteLine("<SequenceEntries>"); for (int i = 0; i < patternCount; i++) { writer.WriteLine("<SequenceEntry>"); writer.WriteLine("<IsSectionStart>false</IsSectionStart>"); writer.WriteLine("<Pattern>{0}</Pattern>", i); writer.WriteLine("</SequenceEntry>"); } writer.WriteLine("</SequenceEntries>"); var xPatternSequence = templateRoot.XPathSelectElement("//PatternSequence"); xPatternSequence.XPathSelectElement("SequenceEntries").Remove(); xPatternSequence.Add(XElement.Parse(writer.ToString())); //copy template file to target File.Delete(outPath); File.Copy(templatePath, outPath); var msOutXml = new MemoryStream(); templateRoot.Save(msOutXml); msOutXml.Flush(); msOutXml.Position = 0; var zfOutput = new ICSharpCode.SharpZipLib.Zip.ZipFile(outPath); zfOutput.BeginUpdate(); zfOutput.Add(new Stupid { stream = msOutXml }, "Song.xml"); zfOutput.CommitUpdate(); zfOutput.Close(); //for easier debugging, write patterndata XML //DUMP_TO_DISK(msOutXml.ToArray()) }
public void EndUpdate() { zip.CommitUpdate(); }
public void Save(string FileName, bool OverWrite) { if (System.IO.File.Exists(FileName) && OverWrite == false) { return; } if (System.IO.File.Exists(FileName)) { System.IO.File.Delete(FileName); } #region Generate The XML File StringBuilder _Builder = new StringBuilder("<gg2world "); _Builder.Append("worldname=\""); _Builder.Append(WorldName); _Builder.Append("\" minpoint=\""); _Builder.Append(GetMin().ToString()); _Builder.Append("\" maxpoint=\""); _Builder.Append(GetMax().ToString()); _Builder.Append("\" >\r\n"); // Append Screen Info foreach (var S in Screens.Values) { _Builder.Append("\t" + S.ExportToXML()); } _Builder.Append("</gg2world>\r\n"); #endregion // Get the Static Variables for the Save Operations string _BaseDirectory = FileName.Substring(0, FileName.LastIndexOf("\\")); Guid _TmpDirGuid = Guid.NewGuid(); string _TmpDir = _TmpDirGuid.ToString().Substring(0, 10); // Create Directory If Needed if (!System.IO.Directory.Exists(_BaseDirectory)) { System.IO.Directory.CreateDirectory(_BaseDirectory); } // Write the XML File System.IO.File.AppendAllText(FileName, _Builder.ToString()); // Create the TempDirectories System.IO.Directory.CreateDirectory(_BaseDirectory + "\\" + _TmpDir + "_Back" + "\\"); System.IO.Directory.CreateDirectory(_BaseDirectory + "\\" + _TmpDir + "_Pass" + "\\"); System.IO.Directory.CreateDirectory(_BaseDirectory + "\\" + _TmpDir + "_Objects" + "\\"); // Save All Images in Zip File to Temp Directory foreach (var S in Screens.Keys) { var _Screen = Screens[S]; //_Screen.BackgroundImage.Save(_BaseDirectory + "\\" + _TmpDir + "_Back" + "\\" + S + "_Back.png"); //_Screen.PassableLayer.Save(_BaseDirectory + "\\" + _TmpDir + "_Pass" + "\\" + S + "_Pass.png"); //GG2DLib.ResourceManager.ImageMethods.SaveImageAsJpg(_Screen.BackgroundImage, _BaseDirectory + "\\" + _TmpDir + "_Back" + "\\" + S + "_Back.png", 95L); //GG2DLib.ResourceManager.ImageMethods.SaveImageAsJpg(_Screen.PassableLayer, _BaseDirectory + "\\" + _TmpDir + "_Pass" + "\\" + S + "_Pass.png", 95L); // _Screen.BackgroundImage.Save(_BaseDirectory + "\\" + _TmpDir + "_Back" + "\\" + S + "_Back.jpg", jgpEncoder, _Params); //_Screen.PassableLayer.Save(_BaseDirectory + "\\" + _TmpDir + "_Pass" + "\\" + S + "_Pass.jpg", jgpEncoder, _Params); } // Save All The Objects foreach (string _K in ResourceManager.GetMapObjectKeys()) { var _TmpImg = ResourceManager.GetMapObjectImageStart(_K); _TmpImg.Save(_BaseDirectory + "\\" + _TmpDir + "_Objects" + "\\" + _K.Substring(_K.LastIndexOf("\\") + 1) + "_Object.png", System.Drawing.Imaging.ImageFormat.Png); ResourceManager.GetMapObjectImageEnd(_K); } // Create The Zip File for the Images if (System.IO.File.Exists(_BaseDirectory + "\\" + WorldName + "_Data.zip")) { System.IO.File.Delete(_BaseDirectory + "\\" + WorldName + "_Data.zip"); } ICSharpCode.SharpZipLib.Zip.ZipFile _Z = ICSharpCode.SharpZipLib.Zip.ZipFile.Create(_BaseDirectory + "\\" + WorldName + "_Data.zip"); // Add The Backgrounds To The Zip File _Z.BeginUpdate(); foreach (string _F in System.IO.Directory.GetFiles(_BaseDirectory + "\\" + _TmpDir + "_Back" + "\\")) { _Z.Add(_F, "Back\\" + _F.Substring(_F.LastIndexOf("\\") + 1)); } _Z.CommitUpdate(); // Add The Passable To The Zip File _Z.BeginUpdate(); foreach (string _F in System.IO.Directory.GetFiles(_BaseDirectory + "\\" + _TmpDir + "_Pass" + "\\")) { _Z.Add(_F, "Pass\\" + _F.Substring(_F.LastIndexOf("\\") + 1)); } _Z.CommitUpdate(); // Add The Objects To The Zip File _Z.BeginUpdate(); foreach (string _F in System.IO.Directory.GetFiles(_BaseDirectory + "\\" + _TmpDir + "_Objects" + "\\")) { _Z.Add(_F, "Objects\\" + _F.Substring(_F.LastIndexOf("\\") + 1)); } _Z.CommitUpdate(); _Z.Close(); // Cleanup Temp Directories System.IO.Directory.Delete(_BaseDirectory + "\\" + _TmpDir + "_Back" + "\\", true); System.IO.Directory.Delete(_BaseDirectory + "\\" + _TmpDir + "_Pass" + "\\", true); System.IO.Directory.Delete(_BaseDirectory + "\\" + _TmpDir + "_Objects" + "\\", true); return; }
private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e) { // Zip up the iso store MemoryStream original = new MemoryStream(); ICSharpCode.SharpZipLib.Zip.ZipFile file = new ICSharpCode.SharpZipLib.Zip.ZipFile(original); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { foreach (string fname in store.GetFileNames()) { file.BeginUpdate(); CustomStaticDataSource sdsf = new CustomStaticDataSource(); var storefile = store.OpenFile(fname, FileMode.Open, FileAccess.Read); storefile.CopyTo(sdsf._stream); storefile.Close(); sdsf._stream.Position = 0; file.Add(sdsf, fname); file.CommitUpdate(); } file.IsStreamOwner = false; file.Close(); original.Position = 0; // Connect to live API LiveAuthClient auth = new LiveAuthClient("00000000440E7119"); auth.InitializeAsync(); auth.InitializeCompleted += (e1, e2) => { // Show login dialog auth.LoginAsync(new string[] { "wl.skydrive_update" }); auth.LoginCompleted += (e3, e4) => { if (e4.Status == LiveConnectSessionStatus.Connected) { LiveConnectClient client = new LiveConnectClient(e4.Session); // Upload that zip we just made client.UploadAsync("me/skydrive/", "wphfolders.zip", original, OverwriteOption.Overwrite); client.UploadCompleted += (ucSender, ucEvent) => { MessageBox.Show("Uploaded wphfolders.zip to the root of your SkyDrive. Feel free to move it, but put it back if you need to restore!"); }; } else { MessageBox.Show("Not connected to SkyDrive"); } }; }; } }
private void deploybtn_click(object sender, EventArgs e) { save(); string filedata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<Deployment xmlns=\"http://schemas.microsoft.com/windowsphone/2009/deployment\" AppPlatformVersion=\"7.1\">" + " <App xmlns=\"\" ProductID=\"{" + Guid.NewGuid().ToString() + "}\" Title=\"" + curMenu.name + "\" RuntimeType=\"Silverlight\" Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"Jaxbot\" Description=\"Folder\" Publisher=\"WindowsPhoneHacker\">" + " <IconPath IsRelative=\"true\" IsResource=\"false\">ApplicationIcon.png</IconPath>" + " <Capabilities>" + " <Capability Name=\"ID_CAP_GAMERSERVICES\"/>" + " <Capability Name=\"ID_CAP_IDENTITY_DEVICE\"/>" + " <Capability Name=\"ID_CAP_IDENTITY_USER\"/>" + " <Capability Name=\"ID_CAP_LOCATION\"/>" + " <Capability Name=\"ID_CAP_MEDIALIB\"/>" + " <Capability Name=\"ID_CAP_MICROPHONE\"/>" + " <Capability Name=\"ID_CAP_NETWORKING\"/>" + " <Capability Name=\"ID_CAP_PHONEDIALER\"/>" + " <Capability Name=\"ID_CAP_PUSH_NOTIFICATION\"/>" + " <Capability Name=\"ID_CAP_SENSORS\"/>" + " <Capability Name=\"ID_CAP_WEBBROWSERCOMPONENT\"/>" + " <Capability Name=\"ID_CAP_ISV_CAMERA\"/>" + " <Capability Name=\"ID_CAP_CONTACTS\"/>" + " <Capability Name=\"ID_CAP_APPOINTMENTS\"/>" + " </Capabilities>" + " <Tasks>" + " <DefaultTask Name =\"_default\" NavigationPage=\"MainPage.xaml\"/>" + " </Tasks>" + " <Tokens>" + " <PrimaryToken TokenID=\"IndependentFolderToken\" TaskName=\"_default\">" + " <TemplateType5>" + " <BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">Background.png</BackgroundImageURI>" + " <Count>0</Count>" + " <Title>Folder</Title>" + " </TemplateType5>" + " </PrimaryToken>" + " </Tokens>" + " </App>" + "</Deployment>"; MemoryStream original = new MemoryStream(); var res = Application.GetResourceStream(new Uri("IndependentFolder.xap", UriKind.Relative)).Stream; res.CopyTo(original); ICSharpCode.SharpZipLib.Zip.ZipFile file = new ICSharpCode.SharpZipLib.Zip.ZipFile(original); file.BeginUpdate(); MemoryStream filestr = new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(filedata)); CustomStaticDataSource sds = new CustomStaticDataSource(); sds.SetStream(filestr); file.Add(sds, "WMAppManifest.xml"); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { foreach (appentry app in curMenu.apps) { var imgfile = store.OpenFile(app.guid + ".jpg", FileMode.Open, FileAccess.Read); CustomStaticDataSource sdsimg = new CustomStaticDataSource(); imgfile.CopyTo(sdsimg._stream); imgfile.Close(); sdsimg._stream.Position = 0; //sdsimg.SetStream(imgfile); file.Add(sdsimg, "apps/" + app.guid + ".jpg"); file.CommitUpdate(); file.BeginUpdate(); } var menufile = store.OpenFile(curMenu.name + ".folder", FileMode.Open, FileAccess.Read); CustomStaticDataSource sdsmenu = new CustomStaticDataSource(); sdsmenu.SetStream(menufile); file.Add(sdsmenu, "menu.folder"); file.CommitUpdate(); file.IsStreamOwner = false; file.Close(); original.Position = 0; using (var stream = new IsolatedStorageFileStream("package." + curMenu.name + ".zip", FileMode.Create, store)) { original.CopyTo(stream); } } /* * ICSharpCode.SharpZipLib.Zip.ZipOutputStream str = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(new MemoryStream()); * str.PutNextEntry(new ICSharpCode.SharpZipLib.Zip.ZipEntry("WMAppManifest.xml")); */ //ICSharpCode.SharpZipLib.Zip.zipout //file.Add(str); XapHandler.XapDeployerInterop.Initialize(); XapHandler.XapDeployerInterop.ReadyIsAppInstalled(@"\Applications\Data\5b594f78-a744-4f8a-85d2-f0f55f411832\Data\IsolatedStore\package." + curMenu.name + ".zip"); XapHandler.XapDeployerInterop.FinishInstall(false); }