예제 #1
0
        private void FixList(List <string> list)
        {
            var bw = new BackgroundWorker();

            bw.WorkerReportsProgress = true;

            bw.DoWork += new DoWorkEventHandler((sender, e) =>
            {
                var filenames = e.Argument as List <string>;
                var progress  = 0;

                var worker = sender as BackgroundWorker;

                foreach (string filename in filenames)
                {
                    IConverter converter = null;

                    if (filename.EndsWith("m2"))
                    {
                        var m2converter = new M2Converter(filename, helmFix.Checked);
                        if (m2converter.Fix())
                        {
                            m2converter.Save();
                        }

                        continue;
                    }
                    else if (filename.EndsWith("adt"))
                    {
                        converter = new ADTFile(filename.Replace(".adt", "_obj0.adt"), filename.Replace(".adt", "_tex0.adt"));
                    }
                    // else if (filename.EndsWith("wdt"))
                    //     converter = new WDTConverter(filename);
                    else if (Regex.IsMatch(filename, @".*_[0-9]{3}(_(lod[0-9]))?\.(wmo)"))
                    {
                        var wmoconverter = new WMOGroupConverter(filename, false);
                        if (wmoconverter.Fix())
                        {
                            wmoconverter.Save();
                        }

                        continue;
                    }
                    else if (filename.EndsWith(".skin"))
                    {
                        continue;
                    }
                    if (filename.EndsWith("wmo"))
                    {
                        converter = new WMOFile();
                    }
                    // else if (filename.EndsWith("anim"))
                    //     converter = new AnimConverter(filename);

                    converter.Read(File.ReadAllBytes(filename));
                    converter.Write(filename);

                    if (++progress == PROGRESS)
                    {
                        worker.ReportProgress(1);
                        progress = 0;
                    }
                }
            });

            bw.ProgressChanged += new ProgressChangedEventHandler((sender, e) =>
            {
                progress.PerformStep();
            });

            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender, e) =>
            {
                if (e.Error != null)
                {
                    MessageBox.Show(e.Error.ToString());
                }

                progress.Value = progress.Maximum;
                Enabled        = true;
                Clear();
            });

            bw.RunWorkerAsync(list);
        }
예제 #2
0
        private void FixList(List <string> list)
        {
            BackgroundWorker bw = new BackgroundWorker();

            bw.WorkerReportsProgress = true;

            if (cb_wod.Checked)
            {
                list.Add("wod");
            }

            bw.DoWork += new DoWorkEventHandler((sender, e) =>
            {
                List <string> items = e.Argument as List <string>;
                List <ConvertionErrorInfo> errors = new List <ConvertionErrorInfo>();
                int progress = 0;

                bool wod = (items[items.Count - 1] == "wod");
                if (wod)
                {
                    items.RemoveAt(items.Count - 1);
                }

                BackgroundWorker worker = sender as BackgroundWorker;

                foreach (string s in items)
                {
                    IConverter converter = null;

                    if (s.EndsWith("m2"))
                    {
                        converter = new M2Converter(s, helm_fix_cb.Checked);
                    }
                    else if (s.EndsWith("adt"))
                    {
                        converter = new AdtConverter(s, adt_water.Checked, adt_models.Checked);
                    }
                    else if (s.EndsWith("wdt"))
                    {
                        converter = new WDTConverter(s);
                    }
                    else if (Regex.IsMatch(s, @".*_[0-9]{3}(_(lod[0-9]))?\.(wmo)"))
                    {
                        converter = new WMOGroupConverter(s, wod);
                    }
                    else if (s.EndsWith("wmo") && !wod)
                    {
                        converter = new WMORootConverter(s);
                    }
                    else if (s.EndsWith("anim"))
                    {
                        converter = new AnimConverter(s);
                    }

                    // ? -> in case a file with a wrong extension/pattern was in the list
                    try
                    {
                        if (converter?.Fix() ?? false)
                        {
                            converter.Save();
                        }
                    }
                    catch (Exception exception)
                    {
                        errors.Add(new ConvertionErrorInfo(exception, s));
                    }

                    if (++progress == PROGRESS)
                    {
                        worker.ReportProgress(1);
                        progress = 0;
                    }
                }

                e.Result = errors;
            });

            bw.ProgressChanged += new ProgressChangedEventHandler((sender, e) =>
            {
                progress.PerformStep();
                converted++;
            });

            List <ConvertionErrorInfo> error_to_log = new List <ConvertionErrorInfo>();

            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender, e) =>
            {
                if (e.Error != null)
                {
                    MessageBox.Show(e.Error.ToString());
                }

                List <ConvertionErrorInfo> errors = e.Result as List <ConvertionErrorInfo>;
                error_to_log.AddRange(errors);

                if ((--threadRemaining) == 0)
                {
                    progress.Value = progress.Maximum;
                    Enabled        = true;
                    Clear();

                    if (error_to_log.Count > 0)
                    {
                        MessageBox.Show(error_to_log.Count + " error(s) while converting files, please send the error.log file to the developper so this issue can be fixed");

                        using (StreamWriter sw = new StreamWriter("error.log", true))
                        {
                            foreach (ConvertionErrorInfo error in error_to_log)
                            {
                                sw.WriteLine("Error fixing: " + error.filename);
                                sw.WriteLine(error.exception.Message);
                                sw.WriteLine(error.exception.StackTrace);
                            }
                        }
                    }
                }
            });

            bw.RunWorkerAsync(list);
        }
예제 #3
0
        public void Run()
        {
            if (files_to_convert.Count == 0)
            {
                Console.WriteLine("No files to convert.");
                return;
            }

            Console.WriteLine("Converting {0} files...", files_to_convert.Count);

            int errors = 0;

            using (StreamWriter sw = new StreamWriter("error.log", false))
            {
                foreach (string s in files_to_convert)
                {
                    IConverter converter = null;

                    if (s.EndsWith("m2"))
                    {
                        converter = new M2Converter(s, FixHelm);
                    }
                    else if (s.EndsWith("adt"))
                    {
                        converter = new AdtConverter(s, AdtWater, AdtModels);
                    }
                    else if (s.EndsWith("wdt"))
                    {
                        converter = new WDTConverter(s);
                    }
                    else if (Regex.IsMatch(s, @".*_[0-9]{3}(_(lod[0-9]))?\.(wmo)"))
                    {
                        converter = new WMOGroupConverter(s, false);
                    }
                    else if (s.EndsWith("wmo"))
                    {
                        converter = new WMORootConverter(s);
                    }
                    else if (s.EndsWith("anim"))
                    {
                        converter = new AnimConverter(s);
                    }

                    try
                    {
                        // ? -> in case a file with a wrong extension/pattern was in the list
                        if (converter?.Fix() ?? false)
                        {
                            converter.Save();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error fixing: " + s);
                        sw.WriteLine("Error fixing: " + s);
                        sw.WriteLine(e.Message);
                        sw.WriteLine(e.StackTrace);
                        errors++;
                    }
                }
            }

            files_to_convert.Clear();

            if (errors > 0)
            {
                Console.WriteLine("{0} error(s) while converting files, please send the error.log file to the developper so this issue can be fixed", errors);
            }

            Console.WriteLine("Done.");
        }