Ejemplo n.º 1
0
        private void ReadUpgDTA(string dta)
        {
            if (!File.Exists(dta))
            {
                return;
            }

            var sr = new StreamReader(dta, Encoding.Default);

            // read one line at a time until the end
            while (sr.Peek() >= 0)
            {
                var line = sr.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                if (line.ToLowerInvariant().Contains("real_bass") && !line.Contains("tuning"))
                {
                    probassdiff = line;
                }
                else if (line.ToLowerInvariant().Contains("real_guitar") && !line.Contains("tuning"))
                {
                    proguitardiff = line;
                }
                else if (line.Contains("real_guitar") && line.Contains("tuning"))
                {
                    proguitartuning = line;
                }
                else if (line.Contains("real_bass") && line.Contains("tuning"))
                {
                    probasstuning = line;
                }
                else if (line.Contains("song_id"))
                {
                    upgradeID = Parser.GetSongID(line);
                }
            }
            sr.Dispose();
            CheckIDMatch();
            Log("Upgrades.dta file processed successfully");
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }