Exemplo n.º 1
0
        static int Main(string[] in_args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool   bGenerateMode                   = false;
            bool   bHideProgressUI                 = false;
            string szInfoFile                      = "";
            string szLayoutFile                    = "";
            string szSpecifiedLanguage             = "";
            CmdLinePackageSettings cmdLineSettings = new CmdLinePackageSettings();

            for (int i = 0; i < in_args.Length; i++)
            {
                if (0 == String.Compare(in_args[i], "-generate", true))
                {
                    bGenerateMode = true;
                }
                else if (0 == String.Compare(in_args[i], "-info", true))
                {
                    if (i < in_args.Length - 1)
                    {
                        szInfoFile = in_args[i + 1];
                    }
                }
                else if (0 == String.Compare(in_args[i], "-layout", true))
                {
                    try
                    {
                        if (i < in_args.Length - 1)
                        {
                            szLayoutFile = in_args[i + 1];
                        }
                        else
                        {
                            throw new Exception("Value expected.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error -layout: " + ex.Message, APP_NAME);
                        return(1);
                    }
                }
                else if (0 == String.Compare(in_args[i], "-output", true))
                {
                    if (i < in_args.Length - 1)
                    {
                        cmdLineSettings.FilePackage = in_args[i + 1];
                    }
                }
                else if (0 == String.Compare(in_args[i], "-blocksize", true))
                {
                    try
                    {
                        if (i < in_args.Length - 1)
                        {
                            cmdLineSettings.DefaultBlockSize = uint.Parse(in_args[i + 1]);
                        }
                        else
                        {
                            throw new Exception("Value expected.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error -blocksize: " + ex.Message, APP_NAME);
                        return(1);
                    }
                }
                else if (0 == String.Compare(in_args[i], "-hideprogressui", true))
                {
                    try
                    {
                        if (i < in_args.Length - 1)
                        {
                            bHideProgressUI = bool.Parse(in_args[i + 1]);
                        }
                        else
                        {
                            throw new Exception("Value expected.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error -hideprogressui: " + ex.Message, APP_NAME);
                        return(1);
                    }
                }
                else if (0 == String.Compare(in_args[i], "-SpecifiedLanguage", true))
                {
                    if (i < in_args.Length - 1)
                    {
                        szSpecifiedLanguage = in_args[i + 1];
                    }
                }
            }

            if (bGenerateMode)
            {
                GenerateModeAppContext appCtx = new GenerateModeAppContext();
                int iReturn = appCtx.Generate(szInfoFile, szLayoutFile, cmdLineSettings, bHideProgressUI, szSpecifiedLanguage);
                if (appCtx.RunApplicationLoop)
                {
                    Application.Run(appCtx);
                }
                return(iReturn);
            }
            else
            {
                Application.Run(new EditModeForm());
                return(0);
            }
        }
Exemplo n.º 2
0
        public int Generate(string in_szInfoFile, string in_szLayoutFile, CmdLinePackageSettings in_cmdLineSettings, bool in_bHideProgressUI, string in_szSpecifiedLanguage)
        {
            FilePackageGenerator generator = new FilePackageGenerator();

            // Display the progress bar (and log) only if the verbose switch was specified.
            if (!in_bHideProgressUI)
            {
                m_progressDlg = new Progress();

                generator.StepChange += m_progressDlg.ProgressStepHandler;
                generator.SubStep    += m_progressDlg.StepHandler;
                generator.LogMsg     += m_progressDlg.LogMsgHandler;

                m_progressDlg.StopRequested += generator.StopRequestedHandler;
                m_progressDlg.Closed        += new EventHandler(OnUIClosed);

                m_progressDlg.Show();
            }

            int iReturn = 0;

            try
            {
                // In order to successfully start packaging:
                // - an info file must have been specified;
                // - either the file package name OR a layout file must have been specified.
                if (in_szInfoFile.Length > 0 &&
                    (in_cmdLineSettings.FilePackagePathSpecified || in_szLayoutFile.Length > 0))
                {
                    SoundBanksInfo data = InfoFileHelpers.LoadInfoFile(in_szInfoFile, in_szSpecifiedLanguage);
                    if (data != null)
                    {
                        PackageSettings    settings;
                        List <OrderedFile> listOrderedFiles = null;
                        if (in_szLayoutFile.Length > 0)
                        {
                            PackagingEditorModel layoutModel = new PackagingEditorModel();
                            layoutModel.LoadLayout(in_szLayoutFile);

                            listOrderedFiles = layoutModel.OrderedFiles;
                            settings         = layoutModel.Settings;

                            // Override layout's settings with each command line setting that was specified.
                            in_cmdLineSettings.OverrideSettingsWithCmdLine(ref settings);
                        }
                        else
                        {
                            settings = in_cmdLineSettings.GetSettings();
                        }

                        bool bNoFileMissing = generator.Generate(data, settings, listOrderedFiles);

                        // Do not display warning if the user does not wish to see UI.
                        if (m_progressDlg != null)
                        {
                            if (!bNoFileMissing)
                            {
                                m_progressDlg.LogMsg("WARNING: some files referenced in " + in_szInfoFile + " could not be found.");
                            }
                            m_progressDlg.LogMsg("SUCCESSFUL file package generation: " + settings.szFilePackageFilename);
                        }
                    }
                }
                else
                {
                    string szInvalidParam = "";
                    if (in_szInfoFile.Length == 0)
                    {
                        szInvalidParam = "No info file specified (-info).\n";
                    }
                    if (!in_cmdLineSettings.FilePackagePathSpecified || in_szLayoutFile.Length == 0)
                    {
                        szInvalidParam += "Neither the output file path (-output) or a layout file (-layout) was specified.\n";
                    }
                    throw new Exception("Some of the required input parameters are not valid:\n" + szInvalidParam);
                }
            }
            catch (Exception ex)
            {
                if (m_progressDlg != null)
                {
                    m_progressDlg.LogMsg("File packaging FAILED! " + ex.Message);
                    MessageBox.Show("File packaging FAILED!\n\n" + ex.Message, Program.APP_NAME);
                }
                iReturn = 1;
            }

            if (m_progressDlg != null)
            {
                // Has UI. Let user know that it should run the message loop until the user closes the form.
                m_progressDlg.Finished();
                m_bRunApplicationLoop = true;
            }
            else
            {
                // No UI. Let user know that it does not need to start the message loop.
                m_bRunApplicationLoop = false;
            }

            return(iReturn);
        }