コード例 #1
0
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            GenhCreatorStruct genhCreatorStruct = (GenhCreatorStruct)e.Argument;

            this.createGenhs(genhCreatorStruct, e);
        }
コード例 #2
0
        private void createGenhs(GenhCreatorStruct pGenhCreatorStruct, DoWorkEventArgs e)
        {
            int progress;
            GenhCreationStruct genhCreationStruct;

            this.maxFiles = pGenhCreatorStruct.SourcePaths.Length;

            string        outputFilePath = String.Empty;
            string        extractedFilePath;
            string        outputMessageAction = String.Empty;
            StringBuilder outputMessage       = new StringBuilder();

            int progressReportingPercentage = 10;
            int progressReportingPercentageIncrementValue = 10;

            foreach (string file in pGenhCreatorStruct.SourcePaths)
            {
                progress = (++this.fileCount * 100) / this.maxFiles;

                // throttle output to prevent locking up the GUI
                if ((progress > progressReportingPercentage) ||
                    (this.fileCount == this.maxFiles))
                {
                    this.progressStruct.Clear();
                    this.progressStruct.FileName = file;
                    ReportProgress(progress, this.progressStruct);
                }

                if (File.Exists(file))
                {
                    if (pGenhCreatorStruct.DoExtract)
                    {
                        outputFilePath      = GenhUtil.ExtractGenhFile(file, true, true, true);
                        outputMessageAction = "Extracted";
                    }
                    else
                    {
                        genhCreationStruct = pGenhCreatorStruct.ToGenhCreationStruct();

                        if (pGenhCreatorStruct.DoCreation)
                        {
                            outputFilePath      = GenhUtil.CreateGenhFile(file, genhCreationStruct);
                            outputMessageAction = "Created";
                        }
                        else if (pGenhCreatorStruct.DoEdit)
                        {
                            extractedFilePath = GenhUtil.ExtractGenhFile(file, false, false, false);

                            if (!String.IsNullOrEmpty(extractedFilePath))
                            {
                                genhCreationStruct.SourcePaths    = new string[1];
                                genhCreationStruct.SourcePaths[0] = extractedFilePath;

                                outputFilePath = GenhUtil.CreateGenhFile(extractedFilePath, genhCreationStruct);

                                File.Delete(extractedFilePath);
                            }

                            outputMessageAction = "Edited";
                        }
                    }

                    if (!String.IsNullOrEmpty(outputFilePath))
                    {
                        outputMessage.AppendFormat("{0} {1}.{2}", outputFilePath, outputMessageAction, Environment.NewLine);
                    }

                    // throttle output to prevent locking up the GUI
                    if ((progress > progressReportingPercentage) ||
                        (this.fileCount == this.maxFiles))
                    {
                        progressReportingPercentage += progressReportingPercentageIncrementValue;

                        this.progressStruct.Clear();
                        this.progressStruct.GenericMessage = outputMessage.ToString();
                        ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);

                        outputMessage.Length = 0;
                    }
                }
            }
        }