Ejemplo n.º 1
0
        private static void MergeThread(object o)
        {
#if TEST_AS_FRENCH
            Tools.SetThreadToFrench();
#endif
            MergeThreadParams mtp     = (MergeThreadParams)o;
            WaitDlg           dlg     = mtp.dlg;
            List <string>     inFiles = mtp.files;
            string            fileDir = Path.GetDirectoryName(inFiles[0]);
            inFiles.Sort(new LogicalComparer(fileDir.Length));
            try
            {
                Stopwatch sw = new Stopwatch();
                using (Archiver archive = new Archiver(mtp.outFile, mtp.fileAlignment))
                {
                    sw.Start();
                    dlg.UpdateStatus("Adding {0} files", inFiles.Count);
                    archive.AddFiles(inFiles, mtp.compression);
                    dlg.UpdateStatus("Waiting for completion");
                    archive.Finish();
                    sw.Stop();
                }
                dlg.AllowClose("Completed in {0:F2} seconds", sw.Elapsed.TotalSeconds);
            }
            catch (Exception e)
            {
                string exception = String.Format("Failed with exception {0} during merge of {1} files", e.Message, inFiles.Count);
                dlg.AllowClose(exception);
                DebugLogger.Log("Merge", exception + "{0}{1}", Environment.NewLine, e.StackTrace);
            }
            GC.Collect();
        }
Ejemplo n.º 2
0
        void RecompressGMFiles(object o)
        {
            RecompressThreadArgs rta = (RecompressThreadArgs)o;
            string inDir             = rta.inDir;

            string[] allFiles     = Directory.GetFiles(inDir);
            int      numFiles     = allFiles.Length;
            WaitDlg  dlg          = rta.dlg;
            string   pngDirectory = Path.Combine(inDir, "bmp");

            dlg.UpdateStatus("Recompressing {0} files", numFiles);
            string outDir   = rta.outDir;
            string gmllFile = @"T:\out.gmll";

            for (int i = 0; i < numFiles; ++i)
            {
                Box.ResetIndexCount();
                string       currentFile = allFiles[i];
                byte[]       gmFileData;
                MemoryStream decompGM;
                using (FileStream fs = File.OpenRead(currentFile))
                {
                    decompGM   = Compress.GZipDecompress(fs);
                    gmFileData = decompGM.ToArray();
                }
                string curFile               = Path.GetFileName(currentFile);
                string pngFile               = Path.Combine(pngDirectory, curFile + ".bmp");
                GTMP.GMFile.GMFileInfo fi    = GTMP.GMFile.Parse(decompGM);
                List <IBox>            boxes = ConvertGMFileBoxes(fi.Boxes);
                if (!Tools.ConvertImageTo(pngFile, gmllFile, Tools.ConvertType.GM))
                {
                    dlg.UpdateStatus(String.Format("Couldn't convert {0} to GT2 foreground, skipping", pngFile));
                    continue;
                }

                try
                {
                    byte[] gmllData    = Images.LoadGMLLData(gmllFile);
                    string newFileName = Path.Combine(outDir, curFile);
                    GMProject.ExportGM(newFileName, boxes, fi.Metadata, gmllData);
                }
                catch (InvalidBoxStateException ibse)
                {
                    DebugLogger.Log("Debug", "Exception was from {0}", currentFile);
                    dlg.UpdateStatus("Caught invalid box exception {0} for {1} in file {2}", ibse.Message, ibse.InvalidBox.Name, currentFile);
                    File.Delete(gmllFile);
                }

                if ((i != 0) && ((i % 100) == 0))
                {
                    dlg.UpdateStatus(String.Format("Tested {0} files", i));
                }
            }
            dlg.AllowClose("All done");
        }
Ejemplo n.º 3
0
        private static void SplitThread(object o)
        {
#if TEST_AS_FRENCH
            Tools.SetThreadToFrench();
#endif
            SplitThreadParams stp = (SplitThreadParams)o;
            WaitDlg           dlg = stp.dlg;
            Stopwatch         sw  = new Stopwatch();
            sw.Start();
            try
            {
                stp.splitter();
                sw.Stop();
                dlg.AllowClose("Completed in {0:F2} seconds", sw.Elapsed.TotalSeconds);
            }
            catch (Exception e)
            {
                string exception = String.Format("Failed with exception {0} during split ", e.Message);
                dlg.AllowClose(exception);
                DebugLogger.Log("Split", exception + "{0}{1}", Environment.NewLine, e.StackTrace);
            }
            sw.Stop();
            GC.Collect();
        }
Ejemplo n.º 4
0
        void CheckGMFileValidity(object o)
        {
            ValidityThreadArgs vta = (ValidityThreadArgs)o;
            string             dir = vta.dir;

            string[] allFiles = Directory.GetFiles(dir);
            int      numFiles = allFiles.Length;
            WaitDlg  dlg      = vta.dlg;

            dlg.UpdateStatus("Checking {0} files", numFiles);
            int exceptions = 0;

            for (int i = 0; i < numFiles; ++i)
            {
                Box.ResetIndexCount();
                string currentFile           = allFiles[i];
                GTMP.GMFile.GMFileInfo fi    = GTMP.GMFile.Parse(currentFile);
                List <IBox>            boxes = ConvertGMFileBoxes(fi.Boxes);

                try
                {
                    MemoryStream ms = new MemoryStream(boxes.Count * 0x4c);
                    using (BinaryWriter bw = new BinaryWriter(ms))
                    {
                        foreach (IBox b in boxes)
                        {
                            b.Serialize(bw);
                        }
                    }
                }
                catch (InvalidBoxStateException ibse)
                {
                    if (++exceptions == 50)
                    {
                        break;
                    }
                    DebugLogger.Log("Debug", "Exception was from {0}", currentFile);
                    dlg.UpdateStatus("Caught invalid box exception {0} for {1} in file {2}", ibse.Message, ibse.InvalidBox.Name, currentFile);
                }

                if ((i != 0) && ((i % 10) == 0))
                {
                    dlg.UpdateStatus(String.Format("Tested {0} files", i));
                }
            }
            dlg.AllowClose("All checked");
        }