Exemplo n.º 1
0
        public bool SaveNewEncodedFile()
        {
            if (this.CurrentMap.HasErrors)
            {
                MessageBox.Show($"Map contains errors, please find and resolve with View > Errors before saving.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            var saveFileDialog = new CommonSaveFileDialog
            {
                RestoreDirectory   = false,
                InitialDirectory   = Directory.GetCurrentDirectory() + "\\data\\",
                DefaultExtension   = "she",
                NavigateToShortcut = true,
                OverwritePrompt    = true,
                DefaultFileName    = Path.GetFileName(this.LoadedMapPath),
                Title = "Save .she"
            };

            saveFileDialog.Filters.Add(new CommonFileDialogFilter("Encoded Map File", "*.she"));
            saveFileDialog.Filters.Add(new CommonFileDialogFilter("All Files", "*.*"));

            var dialogSuccess = saveFileDialog.ShowDialog();

            if (dialogSuccess == CommonFileDialogResult.Ok)
            {
                TCDEncodeDecode.SaveFile(saveFileDialog.FileName, TCDEncodeDecode.EncodeMap(this.CurrentMap.StringValue));
                this.LoadedMapPath = saveFileDialog.FileName;
                this.LastLoadedMap = (Map)this.CurrentMap.Clone();

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public bool SaveOrCreateEncodedFile()
        {
            var success = false;

            if (this.LoadedMapPath == null)
            {
                success = this.SaveNewEncodedFile();
            }
            else
            {
                var shdFile = Path.ChangeExtension(this.LoadedMapPath, ".she");
                success            = TCDEncodeDecode.SaveFile(shdFile, TCDEncodeDecode.EncodeMap(this.CurrentMap.StringValue));
                this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            }

            return(success);
        }
Exemplo n.º 3
0
        public static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Invalid arguments, expected \"ResourcePackingBuildStep.exe <pack|encode> <packed directory> <output file prefix|directory>\"");
                return(-1);
            }

            if (args[0] == "pack")
            {
                var packComplete = false;
                TCDEncodeDecode.PackTCDFile(
                    args[1],
                    args[2],
                    (fileName, progress) =>
                {
                    if (fileName != null)
                    {
                        Console.WriteLine($"({100 * progress:F1}%) {fileName}");
                    }
                    else
                    {
                        packComplete = true;
                    }
                });

                while (!packComplete)
                {
                    Thread.Sleep(1);
                }

                Console.WriteLine($"(100.0%) Directory packed into:");
                Console.WriteLine($"         > {args[1]}Resource.tcd");
                Console.WriteLine($"         > {args[1]}Pattern.tcd");
            }
            else if (args[0] == "encode")
            {
                Directory.CreateDirectory(args[2]);

                var mapfiles = Directory.GetFiles(args[1]);

                for (int i = 0; i < mapfiles.Length; i++)
                {
                    var map             = mapfiles[i];
                    var contents        = TCDEncodeDecode.ReadTextFile(map, false);
                    var encodedContents = TCDEncodeDecode.EncodeMap(contents);

                    var filename = Path.GetFileNameWithoutExtension(map);
                    var newPath  = Path.Combine(args[2], Path.ChangeExtension(filename, ".she"));
                    TCDEncodeDecode.SaveFile(newPath, encodedContents);

                    Console.WriteLine($"({100 * ((double)i / mapfiles.Length):F1}%) {filename}");
                }

                Console.WriteLine($"(100.0%) Map files encoded to directory:");
                Console.WriteLine($"         > {args[2]}");
            }
            else
            {
                Console.Error.WriteLine($"Invalid operation \"{args[0]}\", expected \"pack\" or \"encode\"");
                return(-1);
            }


            return(0);
        }