コード例 #1
0
        protected void ReplaceTextureFile(string newFilePath)
        {
            var vm          = CollectionViewSource.GetDefaultView(OpenFiles).CurrentItem as EdataFileViewModel;
            var destTgvFile = vm?.FilesCollectionView.CurrentItem as EdataContentFile;

            if (destTgvFile == null)
            {
                return;
            }

            var tgvReader = new TgvReader();
            var data      = vm.EdataManager.GetRawData(destTgvFile);
            var tgv       = tgvReader.Read(data);

            var             dispatcher = Dispatcher.CurrentDispatcher;
            Action <string> report     = msg => StatusText = msg;

            var s = new Task(() =>
            {
                try
                {
                    dispatcher.Invoke(() => IsUIBusy = true);
                    dispatcher.Invoke(report, $"Replacing {destTgvFile.Path}...");

                    byte[] sourceDds = File.ReadAllBytes(newFilePath);

                    dispatcher.Invoke(report, "Converting DDS to TGV file format...");

                    var ddsReader     = new TgvDDSReader();
                    var sourceTgvFile = ddsReader.ReadDDS(sourceDds);
                    byte[] sourceTgvRawData;

                    using (var tgvwriterStream = new MemoryStream())
                    {
                        var tgvWriter = new TgvWriter();
                        tgvWriter.Write(tgvwriterStream, sourceTgvFile, tgv.SourceChecksum, tgv.IsCompressed);
                        sourceTgvRawData = tgvwriterStream.ToArray();
                    }

                    dispatcher.Invoke(report, "Replacing file in edata container...");

                    vm.EdataManager.ReplaceFile(destTgvFile, sourceTgvRawData);

                    vm.LoadFile(vm.LoadedFile);
                    dispatcher.Invoke(report, "Ready");
                }
                catch (Exception ex)
                {
                    dispatcher.Invoke(report, $"Replacing failed {ex.Message}");
                    Trace.TraceError("Unhandeled exception in Thread occoured: {0}", ex.ToString());
                }
                finally
                {
                    dispatcher.Invoke(() => IsUIBusy = false);
                }
            });

            s.Start();
        }
コード例 #2
0
        protected void ExportTextureExecute(object obj)
        {
            var vm = CollectionViewSource.GetDefaultView(OpenFiles).CurrentItem as EdataFileViewModel;

            if (vm == null)
            {
                return;
            }

            var sourceTgvFile = vm.FilesCollectionView.CurrentItem as EdataContentFile;

            if (sourceTgvFile == null)
            {
                return;
            }

            var             dispatcher = Dispatcher.CurrentDispatcher;
            Action <string> report     = msg => StatusText = msg;

            var s = new Task(() =>
            {
                try
                {
                    dispatcher.Invoke(() => IsUIBusy = true);

                    Settings settings = SettingsManager.Load();

                    var f          = new FileInfo(sourceTgvFile.Path);
                    var exportPath = Path.Combine(settings.SavePath, f.Name + ".dds");

                    dispatcher.Invoke(report, string.Format("Exporting to {0}...", exportPath));

                    var tgvReader = new TgvReader();
                    var tgv       = tgvReader.Read(vm.EdataManager.GetRawData(sourceTgvFile));

                    var writer = new TgvDDSWriter();

                    byte[] content = writer.CreateDDSFile(tgv);

                    using (var fs = new FileStream(Path.Combine(settings.SavePath, f.Name + ".dds"), FileMode.OpenOrCreate))
                    {
                        fs.Write(content, 0, content.Length);
                        fs.Flush();
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Unhandeled exception in Thread occoured: {0}", ex.ToString());
                }
                finally
                {
                    dispatcher.Invoke(report, "Ready");
                    dispatcher.Invoke(() => IsUIBusy = false);
                }
            });

            s.Start();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //var inpath = @"C:\Users\Anders\wargameexport\port_Wonsan";
            //var inFile = Path.Combine(inpath, "lowdef.tmst_chunk_pc");
            if (args == null || args.Length == 0)
            {
                return;
            }
            var inFile    = args[0];
            var inpath    = Directory.GetCurrentDirectory();
            var tgvReader = new TgvReader();

            var inFileInfo = new FileInfo(inFile);

            TgvFile tgv;

            using (var fs = new FileStream(inFile, FileMode.Open))
            {
                var writer = new TgvDDSWriter();

                int index = 1;

                const uint fatMagic = 810828102;
                Console.WriteLine("start");

                while (fs.Position + 4 < fs.Length)
                {
                    fs.Seek(4, SeekOrigin.Current);

                    var buffer = new byte[4];
                    fs.Read(buffer, 0, buffer.Length);

                    if (BitConverter.ToUInt32(buffer, 0) != fatMagic)
                    {
                        break;
                    }

                    // Always 1
                    fs.Read(buffer, 0, buffer.Length);
                    uint int1 = BitConverter.ToUInt32(buffer, 0);

                    // Always 16
                    fs.Read(buffer, 0, buffer.Length);
                    uint int2 = BitConverter.ToUInt32(buffer, 0);

                    //Console.WriteLine("{0} - {1}", int1, int2);

                    //fs.Seek(8, SeekOrigin.Current);

                    fs.Read(buffer, 0, buffer.Length);
                    var blockSize = BitConverter.ToUInt32(buffer, 0);

                    if (fs.Position >= fs.Length)
                    {
                        continue;
                    }

                    var tileBuffer = new byte[blockSize];

                    fs.Read(tileBuffer, 0, tileBuffer.Length);

                    tgv = tgvReader.Read(tileBuffer);
                    Console.WriteLine(index);
                    byte[] content = writer.CreateDDSFile(tgv);

                    var f = new FileInfo(inFile);

                    var path = Path.Combine(inpath, string.Format("{0}_{1}", f.Name, "export"));

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    //if (index%21==3)
                    using (var outFs = new FileStream(Path.Combine(path, string.Format("{0}.dds", index)), FileMode.OpenOrCreate))
                    {
                        outFs.Write(content, 0, content.Length);
                        outFs.Flush();
                    }

                    index++;
                }
            }
        }
コード例 #4
0
        protected void ReplaceTextureExecute(object obj)
        {
            var vm = CollectionViewSource.GetDefaultView(OpenFiles).CurrentItem as EdataFileViewModel;

            if (vm == null)
            {
                return;
            }

            var destTgvFile = vm.FilesCollectionView.CurrentItem as EdataContentFile;

            if (destTgvFile == null)
            {
                return;
            }

            var tgvReader = new TgvReader();
            var data      = vm.EdataManager.GetRawData(destTgvFile);
            var tgv       = tgvReader.Read(data);

            Settings settings = SettingsManager.Load();

            var openfDlg = new OpenFileDialog
            {
                DefaultExt  = ".dds",
                Multiselect = false,
                Filter      = "DDS files (.dds)|*.dds"
            };

            if (File.Exists(settings.LastOpenFolder))
            {
                openfDlg.InitialDirectory = settings.LastOpenFolder;
            }

            if (openfDlg.ShowDialog().Value)
            {
                settings.LastOpenFolder = new FileInfo(openfDlg.FileName).DirectoryName;
                SettingsManager.Save(settings);

                var             dispatcher = Dispatcher.CurrentDispatcher;
                Action <string> report     = msg => StatusText = msg;

                var s = new Task(() =>
                {
                    try
                    {
                        dispatcher.Invoke(() => IsUIBusy = true);
                        dispatcher.Invoke(report, string.Format("Replacing {0}...", destTgvFile.Path));

                        byte[] sourceDds = File.ReadAllBytes(openfDlg.FileName);

                        dispatcher.Invoke(report, "Converting DDS to TGV file format...");

                        var ddsReader     = new TgvDDSReader();
                        var sourceTgvFile = ddsReader.ReadDDS(sourceDds);
                        byte[] sourceTgvRawData;

                        using (var tgvwriterStream = new MemoryStream())
                        {
                            var tgvWriter = new TgvWriter();
                            tgvWriter.Write(tgvwriterStream, sourceTgvFile, tgv.SourceChecksum, tgv.IsCompressed);
                            sourceTgvRawData = tgvwriterStream.ToArray();
                        }

                        dispatcher.Invoke(report, "Replacing file in edata container...");

                        vm.EdataManager.ReplaceFile(destTgvFile, sourceTgvRawData);
                        vm.LoadFile(vm.LoadedFile);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Unhandeled exception in Thread occoured: {0}", ex.ToString());
                    }
                    finally
                    {
                        dispatcher.Invoke(report, "Ready");
                        dispatcher.Invoke(() => IsUIBusy = false);
                    }
                });

                s.Start();
            }
        }
コード例 #5
0
ファイル: UnitTest1.cs プロジェクト: zawecha1/moddingSuite
        public void ExportTmsTest()
        {
            var inpath = @"C:\Users\Anders\wargameexport\r2";
            var inFile = Path.Combine(inpath, "lowdef.tmst_chunk_pc");

            var tgvReader = new TgvReader();

            var inFileInfo = new FileInfo(inFile);

            TgvFile tgv;

            using (var fs = new FileStream(inFile, FileMode.Open))
            {
                var writer = new TgvDDSWriter();

                int index = 1;

                const uint fatMagic = 810828102;
                Console.WriteLine("start");
                while (fs.Position < fs.Length)
                {
                    fs.Seek(4, SeekOrigin.Current);

                    var buffer = new byte[4];
                    fs.Read(buffer, 0, buffer.Length);

                    if (BitConverter.ToUInt32(buffer, 0) != fatMagic)
                    {
                        throw new InvalidDataException();
                    }
                    Console.WriteLine("passe");
                    fs.Seek(8, SeekOrigin.Current);

                    fs.Read(buffer, 0, buffer.Length);
                    var blockSize = BitConverter.ToUInt32(buffer, 0);

                    if (fs.Position >= fs.Length)
                    {
                        continue;
                    }

                    var tileBuffer = new byte[blockSize];

                    fs.Read(tileBuffer, 0, tileBuffer.Length);

                    tgv = tgvReader.Read(tileBuffer);

                    byte[] content = writer.CreateDDSFile(tgv);

                    var f = new FileInfo(inFile);

                    var path = Path.Combine(inpath, string.Format("{0}_{1}", f.Name, "export"));

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    using (var outFs = new FileStream(Path.Combine(path, string.Format("{0}.dds", index)), FileMode.OpenOrCreate))
                    {
                        outFs.Write(content, 0, content.Length);
                        outFs.Flush();
                    }

                    index++;
                }
            }
        }