Example #1
0
        private bool addFiles()
        {
            if (backgroundWorker1.CancellationPending)
            {
                return(false);
            }

            var name = "song";

            if (chkFTV.Checked)
            {
                name = "ftv";
            }

            var filesAdded = 0;

            if (songsFolder.Substring(songsFolder.Length - 1, 1) != "\\")
            {
                songsFolder = songsFolder + "\\";
            }

            if (Directory.Exists(songsFolder))
            {
                var songsInput    = Directory.GetFiles(songsFolder);
                var enoughFolders = Directory.GetDirectories(songsFolder);
                if (enoughFolders.Any()) //only add if there's at least one folder in there
                {
                    packfiles.AddFolder("songs");

                    foreach (var sFile in songsInput.Where(sFile => sFile.Substring(sFile.Length - 4, 4) != ".dta"))
                    {
                        packfiles.AddFile(sFile, "songs/" + Path.GetFileName(sFile));
                    }

                    //create song folders and add contents to each
                    var subFolders    = Directory.GetDirectories(songsFolder);
                    var sFolderLength = songsFolder;

                    //if songs.dta doesn't exist, create one. if exists, leave it, will be appended
                    if (!(File.Exists(songsFolder + "songs.dta")))
                    {
                        var tempDta = new StreamWriter(songsFolder + "songs.dta", false, Encoding.Default);
                        tempDta.Dispose();
                    }

                    foreach (var songName in from folder in subFolders select folder.Substring(sFolderLength.Length, folder.Length - sFolderLength.Length) into songName select songName.Replace("\\", "") into songName where Directory.Exists(songsFolder + songName) let ending = songName.Substring(songName.Length - 3, 3) where ending != "(1)" && ending != "(2)" && ending != "(3)" && ending != "(4)" && ending != "(5)" select songName)
                    {
                        if (backgroundWorker1.CancellationPending)
                        {
                            return(false);
                        }

                        filesAdded++;
                        Log("Adding files for song " + filesAdded);
                        //add all items at the songfolder level (mostly .mid and .mogg files)
                        packfiles.AddFolder("songs/" + songName);

                        //if songs.dta is there, add to main songs.dta and then delete
                        if (File.Exists(songsFolder + songName + "\\songs.dta"))
                        {
                            var dtaIn  = new StreamReader(songsFolder + songName + "\\songs.dta", Encoding.Default);
                            var dtaOut = new StreamWriter(songsFolder + "songs.dta", true, Encoding.Default);

                            while (dtaIn.Peek() >= 0)
                            {
                                var line = dtaIn.ReadLine();

                                if (string.IsNullOrWhiteSpace(line))
                                {
                                    continue;
                                }
                                line = Tools.FixBadChars(line);

                                if (chkID.Checked)
                                {
                                    //replace short id with custom generated id
                                    if (line == "(")
                                    {
                                        dtaOut.WriteLine(line);
                                        dtaIn.ReadLine();

                                        var month = "0" + nextFriday.Month;
                                        month = month.Substring(month.Length - 2, 2);
                                        var day = "0" + nextFriday.Day;
                                        day = day.Substring(day.Length - 2, 2);

                                        line = "      '" + month + day +
                                               nextFriday.Year.ToString(CultureInfo.InvariantCulture)
                                               .Substring(2, 2) + name + filesAdded + "'";
                                    }
                                    else if (!string.IsNullOrWhiteSpace(line) && (line.Substring(0, 1) == "(" && !line.Contains(")")))
                                    {
                                        line = "(" + nextFriday.Month + nextFriday.Day +
                                               nextFriday.Year.ToString(CultureInfo.InvariantCulture)
                                               .Substring(2, 2) + name + filesAdded;
                                    }
                                }

                                if (chkRename.Checked)
                                {
                                    var replace = defaultTool.Checked ? "RECORDING" : "PREVIEW";
                                    //replace artist names to group all together
                                    if (line.ToLowerInvariant().Contains("(artist"))
                                    {
                                        line = "   (artist \"VIDEO " + replace + "\")";
                                    }
                                    if (line.ToLowerInvariant().Contains("'artist'"))
                                    {
                                        dtaOut.WriteLine(line);
                                        dtaIn.ReadLine();
                                        line = "      \"VIDEO " + replace + "\"";
                                    }
                                }

                                if (chkID.Checked)
                                {
                                    //replace song id with custom generated id
                                    if (line.Contains("song_id"))
                                    {
                                        line = "   ('song_id' " + nextFriday.Month + nextFriday.Day +
                                               nextFriday.Year.ToString(CultureInfo.InvariantCulture)
                                               .Substring(2, 2) + name + filesAdded + ")";
                                    }
                                }

                                //add mute level setting so all instruments are heard even when missed
                                if ((line.Contains("'drum_freestyle'") || line.Contains("(drum_freestyle")) && chkVolume.Checked)
                                {
                                    if (line.Contains("'drum_freestyle'"))
                                    {
                                        dtaOut.WriteLine(line);
                                        line = dtaIn.ReadLine();
                                        dtaOut.WriteLine(line);
                                        line = dtaIn.ReadLine();
                                        dtaOut.WriteLine(line);
                                        line = dtaIn.ReadLine();
                                        dtaOut.WriteLine(line);
                                        line = dtaIn.ReadLine();
                                        dtaOut.WriteLine(line);
                                        line = dtaIn.ReadLine();
                                        dtaOut.WriteLine(line);
                                    }
                                    else if (line.Contains("(drum_freestyle"))
                                    {
                                        dtaOut.WriteLine(line);
                                        line = dtaIn.ReadLine();
                                        dtaOut.WriteLine(line);
                                        line = dtaIn.ReadLine();
                                        dtaOut.WriteLine(line);
                                    }
                                    dtaOut.WriteLine("      (mute_volume 0.0)");
                                    dtaOut.WriteLine("      (mute_volume_vocals 0.0)");
                                    line = dtaIn.ReadLine();
                                }

                                if (line != null && !line.Trim().StartsWith(";;", StringComparison.Ordinal))
                                {
                                    dtaOut.WriteLine(line);
                                }
                            }
                            dtaIn.Dispose();
                            dtaOut.WriteLine(""); //separate entries
                            dtaOut.Dispose();

                            //delete original dta files
                            Tools.DeleteFile(songsFolder + songName + "\\songs.dta");
                        }

                        //add mid, mogg and other files found at the songname folder level
                        var songContents = Directory.GetFiles(songsFolder + songName);
                        if (songContents.Count() != 0)
                        {
                            foreach (var contents in songContents)
                            {
                                if (backgroundWorker1.CancellationPending)
                                {
                                    return(false);
                                }
                                packfiles.AddFile(contents, "songs/" + songName + "/" + Path.GetFileName(contents));
                            }
                        }

                        //all all items at the gen level (mostly png_xbox and milo_xbox files)
                        packfiles.AddFolder("songs/" + songName + "/gen");
                        var subContents = Directory.GetFiles(songsFolder + songName + "\\gen");
                        if (!subContents.Any())
                        {
                            continue;
                        }
                        foreach (var contents in subContents)
                        {
                            if (backgroundWorker1.CancellationPending)
                            {
                                return(false);
                            }
                            packfiles.AddFile(contents, "songs/" + songName + "/gen/" + Path.GetFileName(contents));
                        }
                    }
                    //C16 modification. if multiple songs.dta files are found, combine them
                    var c16Dta = Directory.GetFiles(songsFolder, "*.dta");
                    if (c16Dta.Count() > 1)
                    {
                        //prompt user that multiple dtas were found, and to choose whether to combine them (C16) or not
                        var dialogResult =
                            MessageBox.Show("Found multiple songs.dta files in the 'songs' folder\nDo you want me to merge (YES) or discard (NO) the duplicates?\nUnless you're C16 or you know what you're doing, I suggest you discard the duplicates (NO)",
                                            "C16 Modification Activate!", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                        switch (dialogResult)
                        {
                        case DialogResult.No:
                            foreach (var c16 in c16Dta.Where(c16 => c16.Substring(c16.Length - 9, 9) != "songs.dta"))
                            {
                                Tools.DeleteFile(c16);
                            }
                            break;

                        case DialogResult.Yes:
                        {
                            //create temporary dta file
                            File.Create(songsFolder + "temp_songs.dta").Dispose();

                            //process the duplicate dtas
                            foreach (var c16 in c16Dta)
                            {
                                //read first dta file
                                var dtaIn   = new StreamReader(c16, Encoding.Default);
                                var dtaPack = dtaIn.ReadToEnd();
                                dtaIn.Dispose();

                                //write to temp dta
                                var dtaOut = new StreamWriter(songsFolder + "temp_songs.dta", true, Encoding.Default);
                                dtaOut.Write(dtaPack);
                                dtaOut.Dispose();

                                //delete that dta file
                                Tools.DeleteFile(c16);
                            }

                            //now rename that to songs.dta and just allow existing code to add it to the package
                            Tools.MoveFile(songsFolder + "temp_songs.dta", songsFolder + "songs.dta");
                        }
                        break;
                        }
                    }

                    if (File.Exists(songsFolder + "songs.dta"))
                    {
                        packfiles.AddFile(songsFolder + "songs.dta", "songs/songs.dta");
                    }
                }
            }

            Log("Successfully added files for " + filesAdded + (filesAdded > 1 ? " songs" : " song"));
            if (filesAdded < inputFiles.Count())
            {
                Log("It looks like there were some duplicate songs");
                Log("I skipped: " + (inputFiles.Count() - filesAdded) + (inputFiles.Count() - filesAdded > 1? " songs" : " song"));
            }

            Tools.DeleteFolder(tempFolder + "temp\\", true);
            return(true);
        }
Example #2
0
        public void LoadCON(string file)
        {
            starting = true;
            if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS)
            {
                MessageBox.Show("That's not a song file ... try again.", "What are you doing?!!?",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            xPackage = new STFSPackage(file);
            if (!xPackage.ParseSuccess)
            {
                Log("Error opening CON file");
                return;
            }

            tabControl1.Enabled = false;
            Log("CON file opened successfully");
            Log("Processing");

            //populate treeview and listview with package contents
            folderTree.AfterSelect += xReturn_NodeClick;
            SetNodes();
            Log("Finished processing the contents");
            Log("Ready.");

            //populate main form with package info
            folder = file;
            Text   = Path.GetFileName(file);
            toolTip1.SetToolTip(chkAutoExtract, "CON file will be extracted to " + file + "_extracted\\");
            txtTitle.Text       = Tools.FixBadChars(xPackage.Header.Title_Display);
            txtDescription.Text = Tools.FixBadChars(xPackage.Header.Description);
            picContent.Image    = xPackage.Header.ContentImage;
            picPackage.Image    = xPackage.Header.PackageImage;

            switch (xPackage.Header.TitleID)
            {
            case 0x45410829:
                cboGameID.SelectedIndex = 0;
                break;

            case 0x45410869:
                cboGameID.SelectedIndex = 1;
                break;

            case 0x45410914:
                cboGameID.SelectedIndex = 2;
                break;

            default:
                cboGameID.Items.Add("Unknown - " + xPackage.Header.TitleID.ToString(CultureInfo.InvariantCulture));
                cboGameID.SelectedIndex = 3;
                cboGameID.Enabled       = false;
                break;
            }

            if (xPackage.Header.ThisType == PackageType.MarketPlace)
            {
                radioLIVE.Checked = true;
            }
            else
            {
                radioCON.Checked = true;
            }

            checkDescription(true);
            tabControl1.Enabled = true;
            starting            = false;
            ShowChanges(false);
        }