Ejemplo n.º 1
0
        /// <summary>
        /// Handler of Generate File Package menu item.
        /// The progress bar dialog is created, displayed, and glued to the notifications of the
        /// file package generator.
        /// The file package generator is launched with the settings stored in the
        /// packaging editor model.
        /// </summary>
        private void generateFilePackageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (m_model.CanPerformPackaging)
            {
                Progress progressDlg = new Progress();

                FilePackageGenerator generator = new FilePackageGenerator();
                generator.StepChange += progressDlg.ProgressStepHandler;
                generator.SubStep    += progressDlg.StepHandler;
                generator.LogMsg     += progressDlg.LogMsgHandler;

                progressDlg.StopRequested += generator.StopRequestedHandler;
                progressDlg.Show();

                try
                {
                    if (!generator.Generate(m_model.InfoData, m_model.Settings, m_model.OrderedFiles))
                    {
                        progressDlg.LogMsg("WARNING: some files referenced in " + m_model.InfoFileName + " could not be found.");
                    }
                    progressDlg.LogMsg("SUCCESSFUL file package generation: " + m_model.Settings.szFilePackageFilename);
                }
                catch (Exception ex)
                {
                    progressDlg.LogMsg("File packaging FAILED! " + ex.Message);
                    MessageBox.Show("File packaging FAILED!\n\n" + ex.Message, Program.APP_NAME);
                }

                progressDlg.Finished();
            }
        }
Ejemplo 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);
        }