Ejemplo n.º 1
0
        static int Main(string[] args)
        {
            try
            {
                Console.SetWindowSize(85, 40);
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Green;
            }
            catch { /* DO NOTHING */ }

#if (DEBUG)
            // give the progie some dumby file to work on
            args = new string[] { "D:\\Temp\\PeppaPig_p.psarc" };
            Console.WriteLine("Running in Debug Mode ... help is not available");
#endif

            // catch if there are no cmd line arguments
            if (args.GetLength(0) == 0)
            {
                args = new string[] { "?" }
            }
            ;
            if (args[0].Contains("?") || args[0].ToLower().Contains("help"))
            {
                Console.WriteLine(@"Tone Liberator DropletApp for Rocksmith 2014 CDLC");
                Console.WriteLine();
                Console.WriteLine(@" - Version: " + ProjectVersion());
                Console.WriteLine(@"   Copyright (C) 2016 CST Developers, Cozy1");
                Console.WriteLine();
                Console.WriteLine(@" - Purpose: Extracts Reusable Tones from CDLC Archive Files");
                Console.WriteLine(@"   Creates 'SongName_Arrangement_ToneKey.tone2014.xml' files");
                Console.WriteLine(@"   and copies them to the 'dlc/toneliberator' output folder");
                Console.WriteLine();
                Console.WriteLine(@" - Usage: Drag/Drop CDLC archive file(s)");
                Console.WriteLine(@"   or folder(s) onto the console executable icon");
                Console.Read();
                return(0);
            }

            var errorMsg   = String.Empty;
            var srcDir     = args[0];
            var rootDir    = Path.GetDirectoryName(srcDir);
            var destFolder = Path.Combine("dlc", "toneliberator");
            var destDir    = Path.Combine(rootDir, destFolder);

            // create destination 'dlc/tones' directory
            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            Console.WriteLine(@"Initializing Tone Liberator CLI ...");
            Console.WriteLine();

            // iterate through folders and/or files
            foreach (var arg in args)
            {
                string[] filePaths;

                if (IsDirectory(arg))
                {
                    filePaths = Directory.GetFiles(arg, "*.psarc", SearchOption.AllDirectories).ToArray();
                    if (!filePaths.Any())
                    {
                        Console.WriteLine(@"<ERROR> No valid PSARC archives found: " + arg);
                        Console.WriteLine();
                        continue;
                    }
                }
                else if (arg.IsValidPSARC())
                {
                    filePaths    = new string[1];
                    filePaths[0] = arg;
                }
                else
                {
                    Console.WriteLine(@"<ERROR> Invalid PSARC archive: " + arg);
                    Console.WriteLine();
                    continue;
                }

                foreach (var filePath in filePaths)
                {
                    Console.WriteLine();
                    Console.WriteLine(@"Liberating tones from: " + filePath);

                    using (var browser = new PsarcLoader(filePath, true))
                    {
                        var jsonEntries = browser.ExtractJsonManifests();
                        foreach (var manifest2014 in jsonEntries)
                        {
                            var preToneKey = String.Empty;
                            var attr       = manifest2014.Entries.ToArray()[0].Value.ToArray()[0].Value;

                            for (int i = 0; i < attr.Tones.Count; i++)
                            {
                                var toneKey = attr.Tones[i].Key;
                                if (toneKey == preToneKey)
                                {
                                    continue;
                                }
                                else
                                {
                                    preToneKey = toneKey;
                                }

                                var toneFileName = String.Format("{0}_{1}.tone2014.xml", attr.FullName, toneKey);
                                var toneFilePath = Path.Combine(destDir, toneFileName);
                                Console.WriteLine(@" - Writing tone: " + toneFilePath);

                                var tone = new Tone2014();
                                tone = attr.Tones[i];
                                tone.Serialize(toneFilePath);
                            }
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@"Done creating tone2014.xml files ...");
            Console.WriteLine(@" - Saved to directory: " + Path.Combine(rootDir, destDir) + @"\");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(@"Press any key to continue ...");
            Console.Read();
            return(0);
        }
        public void TestPackageGenerate()
        {
            var archivePaths = new List <string>();

            foreach (var srcPath in TestSettings.Instance.ResourcePaths)
            {
                Debug.WriteLine("Processing: " + srcPath);
                // load info from srcPath
                DLCPackageData info = new DLCPackageData();

                var platform = srcPath.GetPlatform();
                if (platform.version == GameVersion.RS2012)
                {
                    packageCreator.CurrentGameVersion = GameVersion.RS2012;
                }
                else
                {
                    packageCreator.CurrentGameVersion = GameVersion.RS2014;
                }

                info = packageCreator.PackageImport(srcPath, TestSettings.Instance.TmpDestDir);

                // set package version, old srcPackage may not have it
                packageCreator.PackageVersion = "8";      // make easy to identify
                packageCreator.AppId          = "492988"; // free Bob Marley - Three Little Birds
                // stress test package generation for all platforms
                packageCreator.PlatformPC      = true;
                packageCreator.PlatformXBox360 = true;
                packageCreator.PlatformPS3     = true;
                packageCreator.PlatformMAC     = true;
                // skip testing ddc generation
                // ConfigRepository.Instance()["ddc_autogen"] = "false";

                if (packageCreator.CurrentGameVersion == GameVersion.RS2012)
                {
                    packageCreator.AppId       = "206102"; // free Holiday Song Pack
                    packageCreator.PlatformPS3 = false;
                    packageCreator.PlatformMAC = false;
                }

                // set destPath and test getting the package data
                var archivePath = Path.Combine(TestSettings.Instance.TmpDestDir, Path.GetFileName(srcPath));
                packageCreator.DestPath = archivePath;
                var packageData = packageCreator.PackageGenerate();
                Assert.NotNull(packageData);

                // call background worker method from unit test to avoid threading issues
                packageCreator.GeneratePackage(null, new DoWorkEventArgs(packageData));
                var shortPath = archivePath.Replace("_p.psarc", "").Replace("_m.psarc", "").Replace("_ps3.psarc.edat", "").Replace("_xbox", "").Replace(".dat", "");

                if (packageCreator.CurrentGameVersion == GameVersion.RS2012)
                {
                    if (!File.Exists(shortPath + ".dat"))
                    {
                        Assert.Fail("RS1 PC Package Generation Failed ...");
                    }

                    if (!File.Exists(shortPath + "_xbox"))
                    {
                        Assert.Fail("RS1 Xbox Package Generation Failed ...");
                    }
                }
                else
                {
                    if (!File.Exists(shortPath + "_p.psarc"))
                    {
                        Assert.Fail("PC Package Generation Failed ...");
                    }

                    if (!File.Exists(shortPath + "_m.psarc"))
                    {
                        Assert.Fail("Mac Package Generation Failed ...");
                    }

                    if (!File.Exists(shortPath + "_xbox"))
                    {
                        Assert.Fail("Xbox Package Generation Failed ...");
                    }

                    if (!File.Exists(shortPath + "_ps3.psarc.edat"))
                    {
                        Assert.Fail("PS3 Package Generation Failed ...");
                    }

                    // console files do not contain an AppId
                    if (!info.PS3 && !info.XBox360)
                    {
                        // check if GeneratePackage wrote the new AppId
                        using (var psarcLoader = new PsarcLoader(archivePath, true))
                        {
                            var entryAppId = psarcLoader.ExtractAppId();
                            Assert.AreEqual(packageCreator.AppId, entryAppId);
                        }
                    }
                }

                archivePaths.Add(archivePath);
            }

            Assert.AreEqual(TestSettings.Instance.ResourcePaths.Count, archivePaths.Count);
        }