Example #1
0
        static int Main(string[] args)
        {
            Console.WindowWidth     = 85;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Green;

#if (DEBUG)
            // give the progie some dumby directory to work on for testing
            // args = new string[] { "--input=D:\\Temp\\Test", "--output=D:\\Temp" }; //, "platform=Pc", "version=RS2014" };
            args = new string[] { "D:\\Temp\\Test" };
#endif

            var      arguments = DefaultArguments();
            var      options   = GetOptions(arguments);
            string[] srcDirs   = null;
            options.Parse(args);

            try
            {
                // drag/drop a directory onto executable application
                if (arguments.Input == null && args.GetLength(0) != 0)
                {
                    try
                    {
                        if (args[0].IsDirectory())
                        {
                            srcDirs = args;
                            if (srcDirs.Length == 1)
                            {
                                srcDirs          = Directory.GetDirectories(srcDirs[0]);
                                arguments.Output = Path.GetDirectoryName(srcDirs[0]);
                            }
                            else
                            {
                                arguments.Output = Path.GetDirectoryName(args[0]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowHelpfulError(ex.Message + "  Check that RootFolder structure has SubFolder(s).");
                        return(1); // failure
                    }
                }
                else // command line error checking
                {
                    if (arguments.ShowHelp || args.GetLength(0) == 0)
                    {
                        options.WriteOptionDescriptions(Console.Out);
                        Console.ReadLine();
                        return(-1); // neither success or failure
                    }

                    if (!arguments.Package)
                    {
                        ShowHelpfulError("Must specify the primary command as 'package'");
                        return(1);
                    }

                    if (arguments.Package)
                    {
                        if ((arguments.Input == null && arguments.Input.Length <= 0) || !arguments.Input[0].IsDirectory())
                        {
                            ShowHelpfulError("Must specify and 'input' directory.");
                            return(1);
                        }

                        if (string.IsNullOrEmpty(arguments.Output))
                        {
                            ShowHelpfulError("Must specify an 'output' directory.");
                            return(1);
                        }
                    }

                    if ((arguments.Platform.platform == GamePlatform.None && arguments.Platform.version != GameVersion.None) || (arguments.Platform.platform != GamePlatform.None && arguments.Platform.version == GameVersion.None))
                    {
                        ShowHelpfulError("'platform' argument requires 'version' and vice-versa to define platform.\r\nUse this option only if you have problem with platform auto identifier");
                        return(1);
                    }

                    srcDirs = arguments.Input;
                }

                Console.WriteLine(@"Initializing Package Creator CLI ...");
                Console.WriteLine("");

                var songCount = srcDirs.Length;
                for (int i = 0; i < songCount; i++)
                {
                    Console.WriteLine(@"Parsing Input Directory (" + (i + 1) + @"/" + songCount + @") for CDLC Package Data: " + Path.GetFileName(srcDirs[i]));

                    try
                    {
                        // get package data
                        DLCPackageData packageData = DLCPackageData.LoadFromFolder(srcDirs[i], arguments.Platform, arguments.Platform, false);
                        packageData.AppId = arguments.AppId;
                        packageData.ToolkitInfo.PackageVersion = arguments.Revision;
                        packageData.Name          = Path.GetFileName(srcDirs[i]).GetValidFileName();
                        packageData.Volume        = packageData.Volume == 0 ? Convert.ToInt16(arguments.Decibels) : packageData.Volume;
                        packageData.PreviewVolume = packageData.PreviewVolume == 0 ? Convert.ToInt16(arguments.Decibels) : packageData.PreviewVolume;

                        // check Album Artwork
                        if (arguments.Platform.version == GameVersion.RS2014)
                        {
                            CheckAlbumArt(srcDirs[i], packageData.Name);
                        }

                        // generate CDLC file name
                        var artist = packageData.SongInfo.ArtistSort;
                        var title  = packageData.SongInfo.SongDisplayNameSort;
                        // var destDir = Path.Combine(arguments.Output, Path.GetFileName(srcDirs[i]).GetValidName());
                        var fileName     = StringExtensions.GetValidShortFileName(artist, title, arguments.Revision.Replace(".", "_"), ConfigRepository.Instance().GetBoolean("creator_useacronyms"));
                        var destPath     = Path.Combine(arguments.Output, fileName);
                        var fullFileName = String.Format("{0}{1}.psarc", fileName, DLCPackageCreator.GetPathName(arguments.Platform)[2]);
                        Console.WriteLine(@"Packing: " + Path.GetFileName(fullFileName));
                        Console.WriteLine("");
                        // pack the data
                        DLCPackageCreator.Generate(destPath, packageData, new Platform(arguments.Platform.platform, arguments.Platform.version));
                        packageData.CleanCache();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("");
                        Console.WriteLine(String.Format("Packaging error!\nDirectory: {0}\n{1}\n{2}", srcDirs[i], ex.Message, ex.InnerException));
                        Console.ReadLine();
                    }
                }

                Console.WriteLine(@"All Finished");
                Console.WriteLine(@"Press any key to continue ...");
                Console.ReadLine();
                return(0); // success
            }
            catch (Exception ex)
            {
                ShowHelpfulError(ex.Message);
                return(1); // failure
            }
        }