private void filteringWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { FilteredSongs = new List <SongIndex>(); if (SearchForIDConflicts) { var IDs = new List <SongIndex>(); foreach (var song in Songs) { if (CancelWorkers) { return; } foreach (var ID in IDs) { if (CancelWorkers) { return; } if (!song.SongID.Equals(ID.SongID) || string.IsNullOrEmpty(song.SongID) || string.IsNullOrEmpty(ID.SongID) || song.SongID.Equals("0") || ID.SongID.Equals("0")) { continue; } if (!FilteredSongs.Contains(song)) { FilteredSongs.Add(song); } if (!FilteredSongs.Contains(ID)) { FilteredSongs.Add(ID); } } IDs.Add(song); } } else { foreach (var song in Songs.Where(song => !Parser.IsNumericID(song.SongID))) { if (CancelWorkers) { return; } FilteredSongs.Add(song); } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { foreach (var file in FilesToConvert) { if (backgroundWorker1.CancellationPending) { return; } var replaced = 0; try { var xFile = new STFSPackage(file); if (!xFile.ParseSuccess) { ProblemFiles.Add(file); continue; } var xent = xFile.GetFile("/songs/songs.dta"); if (xent == null) { xFile.CloseIO(); ProblemFiles.Add(file); continue; } var dta1 = Application.StartupPath + "\\bin\\dta1.txt"; Tools.DeleteFile(dta1); if (!xent.Extract(dta1)) { xFile.CloseIO(); ProblemFiles.Add(file); continue; } var dta2 = Application.StartupPath + "\\bin\\dta2.txt"; Tools.DeleteFile(dta2); var sr = new StreamReader(dta1, Encoding.Default); var sw = new StreamWriter(dta2, false, Encoding.Default); while (sr.Peek() >= 0) { var line = sr.ReadLine(); if (string.IsNullOrEmpty(line.Trim())) { continue; } if (line.Contains(";ORIG_ID=")) { if (DoReverseBatch) { var id = line.Replace(";", "").Replace("ORIG_ID=", "").Trim(); sw.WriteLine(" ('song_id' " + id + ")"); sr.ReadLine();//skip the old song_id line line = sr.ReadLine(); TotalSongs++; replaced++; } else { sw.WriteLine(line); line = sr.ReadLine(); sw.WriteLine(line); line = sr.ReadLine(); } } else if (line.Contains("song_id") && !DoReverseBatch) { if (!Parser.IsNumericID(line)) { line = ";ORIG_ID=" + Parser.GetSongID(line); sw.WriteLine(line); line = " ('song_id' " + mMainForm.GetNumericID() + ")"; TotalSongs++; replaced++; } else { SkippedFiles.Add(file); } } if (!string.IsNullOrEmpty(line.Trim())) { sw.WriteLine(line); } } sr.Dispose(); sw.Dispose(); if (replaced == 0) //don't modify this CON file if nothing is edited in this DTA file { if (!SkippedFiles.Contains(file)) { SkippedFiles.Add(file); } xFile.CloseIO(); continue; } if (backgroundWorker1.CancellationPending) { xFile.CloseIO(); return; } if (!xent.Replace(dta2)) { xFile.CloseIO(); ProblemFiles.Add(file); continue; } Tools.DeleteFile(dta1); Tools.DeleteFile(dta2); xFile.Header.MakeAnonymous(); xFile.Header.ThisType = PackageType.SavedGame; var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); xFile.RebuildPackage(signature); xFile.FlushPackage(signature); xFile.CloseIO(); Tools.UnlockCON(file); Tools.SignCON(file); xFile.CloseIO(); } catch (Exception) { ProblemFiles.Add(file); } } }