Пример #1
0
        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++;
                }
            }
        }
Пример #2
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;

                    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++;
                }
            }
        }
        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();
        }