private void SaveMym(bool exitAfter) { if (lbxIniEntries.Items.Count > 0) { SaveSelected(); SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "mym|*.mym"; if (!string.IsNullOrEmpty(openedMym)) { sfd.FileName = openedMym; } if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ReportProgress(0, "Collecting data..."); List <object> lbEntries = new List <object>(); foreach (object entry in lbxIniEntries.Items) { lbEntries.Add(entry); } CreationInfo cInfo = new CreationInfo(); cInfo.savePath = sfd.FileName; cInfo.lbEntries = lbEntries.ToArray(); cInfo.createCsm = false; cInfo.closeAfter = exitAfter; Thread workerThread = new Thread(new ParameterizedThreadStart(this._saveMym)); workerThread.Start(cInfo); } } }
private void CreateCsm(string appFile, string nandBackupAppPath) { SaveSelected(); if (string.IsNullOrEmpty(nandBackupAppPath)) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "csm|*.csm"; if (!string.IsNullOrEmpty(openedMym)) { sfd.FileName = openedMym; } if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ReportProgress(0, "Collecting data..."); List <object> lbEntries = new List <object>(); foreach (object entry in lbxIniEntries.Items) { lbEntries.Add(entry); } CreationInfo cInfo = new CreationInfo(); cInfo.savePath = sfd.FileName; cInfo.lbEntries = lbEntries.ToArray(); cInfo.createCsm = true; cInfo.appFile = appFile; cInfo.closeAfter = false; Thread workerThread = new Thread(new ParameterizedThreadStart(this._saveMym)); workerThread.Start(cInfo); } } else { ReportProgress(0, "Collecting data..."); List <object> lbEntries = new List <object>(); foreach (object entry in lbxIniEntries.Items) { lbEntries.Add(entry); } CreationInfo cInfo = new CreationInfo(); cInfo.savePath = nandBackupAppPath; cInfo.lbEntries = lbEntries.ToArray(); cInfo.createCsm = true; cInfo.appFile = appFile; cInfo.closeAfter = false; Thread workerThread = new Thread(new ParameterizedThreadStart(this._saveMym)); workerThread.Start(cInfo); } }
private void CreateCsm(string appFile, string nandBackupAppPath) { SaveSelected(); if (string.IsNullOrEmpty(nandBackupAppPath)) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "csm|*.csm"; if (!string.IsNullOrEmpty(openedMym)) sfd.FileName = openedMym; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ReportProgress(0, "Collecting data..."); List<object> lbEntries = new List<object>(); foreach (object entry in lbxIniEntries.Items) lbEntries.Add(entry); CreationInfo cInfo = new CreationInfo(); cInfo.savePath = sfd.FileName; cInfo.lbEntries = lbEntries.ToArray(); cInfo.createCsm = true; cInfo.appFile = appFile; cInfo.closeAfter = false; Thread workerThread = new Thread(new ParameterizedThreadStart(this._saveMym)); workerThread.Start(cInfo); } } else { ReportProgress(0, "Collecting data..."); List<object> lbEntries = new List<object>(); foreach (object entry in lbxIniEntries.Items) lbEntries.Add(entry); CreationInfo cInfo = new CreationInfo(); cInfo.savePath = nandBackupAppPath; cInfo.lbEntries = lbEntries.ToArray(); cInfo.createCsm = true; cInfo.appFile = appFile; cInfo.closeAfter = false; Thread workerThread = new Thread(new ParameterizedThreadStart(this._saveMym)); workerThread.Start(cInfo); } }
private void SaveMym(bool exitAfter) { if (lbxIniEntries.Items.Count > 0) { SaveSelected(); SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "mym|*.mym"; if (!string.IsNullOrEmpty(openedMym)) sfd.FileName = openedMym; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ReportProgress(0, "Collecting data..."); List<object> lbEntries = new List<object>(); foreach (object entry in lbxIniEntries.Items) lbEntries.Add(entry); CreationInfo cInfo = new CreationInfo(); cInfo.savePath = sfd.FileName; cInfo.lbEntries = lbEntries.ToArray(); cInfo.createCsm = false; cInfo.closeAfter = exitAfter; Thread workerThread = new Thread(new ParameterizedThreadStart(this._saveMym)); workerThread.Start(cInfo); } } }
private void _saveMym(object _creationInfo) { SetControls(false); CreationInfo cInfo = (CreationInfo)_creationInfo; string outDir = tempDir + "newMym\\"; if (Directory.Exists(outDir)) { Directory.Delete(outDir, true); } Directory.CreateDirectory(outDir); int counter = 0; int[] counters = new int[5]; //Build new ini List <iniEntry> tempEntries = new List <iniEntry>(); List <string[]> dataSources = new List <string[]>(); List <string[]> imageSources = new List <string[]>(); foreach (object tempObject in cInfo.lbEntries) { ReportProgress(++counter * 100 / cInfo.lbEntries.Length, "Building mym.ini..."); try { iniEntry tempEntry = ini.GetEntry(tempObject.ToString()); if (!CheckEntry(tempEntry)) { if (!settings.ignoreMissing) { ReportProgress(100, " "); SetControls(true); return; } else { continue; } } if (settings.sourceManage) { //Manage source if (tempEntry.entryType == iniEntry.EntryType.StaticData) { if (Path.HasExtension(tempEntry.filepath)) { tempEntry.source = "\\" + Path.GetExtension(tempEntry.filepath).Remove(0, 1) + "\\" + Path.GetFileName(tempEntry.filepath); string tempSource = "\\" + Path.GetExtension(tempEntry.filepath).Remove(0, 1) + "\\" + Path.GetFileName(tempEntry.filepath); int i = 1; while (EntryExists(tempEntry, dataSources)) { tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString()); } FileInfo fi = new FileInfo(tempEntry.filepath); dataSources.Add(new string[] { tempEntry.source, fi.Length.ToString() }); } else { tempEntry.source = "\\" + Path.GetFileName(tempEntry.filepath); string tempSource = "\\" + "\\" + Path.GetFileName(tempEntry.filepath); int i = 1; while (EntryExists(tempEntry, dataSources)) { tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString()); } FileInfo fi = new FileInfo(tempEntry.filepath); dataSources.Add(new string[] { tempEntry.source, fi.Length.ToString() }); } } else if (tempEntry.entryType == iniEntry.EntryType.StaticImage) { tempEntry.source = "\\images\\" + Path.GetFileName(tempEntry.filepath); string tempSource = "\\images\\" + Path.GetFileName(tempEntry.filepath); int i = 1; while (EntryExists(tempEntry, imageSources)) { tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString()); } FileInfo fi = new FileInfo(tempEntry.filepath); imageSources.Add(new string[] { tempEntry.source, fi.Length.ToString() }); } } if (settings.autoImageSize) { if (tempEntry.entryType == iniEntry.EntryType.CustomImage || tempEntry.entryType == iniEntry.EntryType.StaticImage) { //Get png width and height Image img = Image.FromFile(tempEntry.filepath); tempEntry.width = img.Width; tempEntry.height = img.Height; } } tempEntries.Add(tempEntry); } catch { } } if (tempEntries.Count < 1) { ErrorBox("No entries left..."); SetControls(true); return; } //Manage Containers if (settings.containerManage) { List <string> containersToManage = new List <string>(); List <string> managedContainers = new List <string>(); foreach (iniEntry tempEntry in tempEntries) { if (tempEntry.entryType == iniEntry.EntryType.Container) { managedContainers.Add(tempEntry.file); } else { if (tempEntry.file.Contains("_out")) { string tmpString = tempEntry.file.Remove(tempEntry.file.IndexOf("_out")); tmpString = tmpString.Substring(0, tmpString.Length - 5) + tmpString.Substring(tmpString.Length - 5).Replace("_", "."); if (!StringExistsInStringArray(tmpString, containersToManage.ToArray())) { containersToManage.Add(tmpString); } } } } List <string> leftContainers = new List <string>(); foreach (string thisContainer in containersToManage) { if (!StringExistsInStringArray(thisContainer, managedContainers.ToArray())) { leftContainers.Add(thisContainer); } } if (leftContainers.Count > 0) { List <iniEntry> newList = new List <iniEntry>(); foreach (string thisContainer in leftContainers) { iniEntry tempEntry = new iniEntry(); tempEntry.entryType = iniEntry.EntryType.Container; tempEntry.file = thisContainer; tempEntry.type = iniEntry.ContainerType.ASH; newList.Add(tempEntry); } newList.AddRange(tempEntries); tempEntries = newList; } } ini = new mymini(); ini.EntryList = tempEntries; ini.Save(outDir + "mym.ini"); counter = 0; //Copy files foreach (iniEntry tempEntry in ini.EntryList) { ReportProgress(++counter * 100 / ini.EntryList.Count, "Copying files..."); if (tempEntry.entryType == iniEntry.EntryType.StaticImage || tempEntry.entryType == iniEntry.EntryType.StaticData) { string sourceFile = tempEntry.filepath; string destFile = outDir + tempEntry.source; if (!Directory.Exists(Path.GetDirectoryName(destFile))) { Directory.CreateDirectory(Path.GetDirectoryName(destFile)); } File.Copy(sourceFile, destFile, true); } } //Zip file ReportProgress(0, "Packing mym..."); ReportProgress(80, ""); // Fake, hm?! FastZip fZip = new FastZip(); fZip.CreateZip((cInfo.createCsm) ? tempDir + "temp.mym" : cInfo.savePath, outDir, true, ""); ReportProgress(100, " "); if (cInfo.closeAfter) { MethodInvoker m = new MethodInvoker(this.ExitApplication); this.Invoke(m); return; } if (!cInfo.createCsm) { InfoBox("Saved mym to:\n" + cInfo.savePath); SetControls(true); return; } _createCsm(cInfo.savePath, cInfo.appFile, tempDir + "temp.mym"); }