Exemple #1
0
        private static void StciToGifWithGifCoder()
        {
            var _fileName = "M_LAW.STI";

            var _input = new FileStream(_fileName, FileMode.Open);

            var _stci = (StciIndexed)StciLoader.LoadStci(_input);

            _input.Close();

            var _gifCoder = Converter.ConvertStciIndexedToGif(_stci, 15, true, 0);

            var _outputFileName = Path.ChangeExtension(_fileName, ".gif");
            var _output         = new FileStream(_outputFileName, FileMode.Create);

            _gifCoder.Save(_output);

            _output.Close();

            _stci = Converter.ConvertGifToStciIndexed(_gifCoder, true, false, 0);

            var _newStiFileName = "NEW_" + _fileName;

            _output = new FileStream(_newStiFileName, FileMode.Create);
            _stci.Save(_output);
            _output.Close();
        }
        public async void Execute(object parameter)
        {
            TestViewModel _viewModel = (TestViewModel)parameter;

            this.IsCanExecute = false;
            this.IsCanExecute = await Task.Run <bool>(() =>
            {
                try
                {
                    _viewModel.StatusString = String.Empty;
                    _viewModel.ResultString = String.Empty;
                    _viewModel.StatusString = String.Empty;

                    _viewModel.ResultString = StciLoader.ReloadStci(_viewModel.FileName);

                    _viewModel.StatusString = "Done";
                }
                catch (Exception exc)
                {
                    _viewModel.ErrorString = Common.GetErrorString(exc);
                }

                return(true);
            });
        }
        private void Convert(string aFileName)
        {
            var _input = new FileStream(aFileName, FileMode.Open);
            var _stci  = (StciIndexed)StciLoader.LoadStci(_input);

            _input.Close();

            var _gifDecoder = Converter.ConvertStciIndexedToGif(
                _stci, (ushort)this.FrameDelay, this.IsTransparentBackground, this.ForeshotingNumber);

            using (var _output = new FileStream(Path.ChangeExtension(aFileName, ".gif"), FileMode.Create))
                _gifDecoder.Save(_output);

            var _fileName = Path.GetFileNameWithoutExtension(aFileName);

            using (var _offsetsFile = File.OpenWrite(_fileName + "_offsets.txt"))
                using (var _sw = new StreamWriter(_offsetsFile))
                {
                    for (int i = 0; i < _stci.Images.Length; i++)
                    {
                        var _img = _stci.Images[i];
                        _sw.Write("{0} {1} {2} {3}/", _img.Header.Width, _img.Header.Height, _img.Header.OffsetX, _img.Header.OffsetY);
                    }
                }
        }
        public async void Execute(object parameter)
        {
            TestViewModel _viewModel = (TestViewModel)parameter;

            this.IsCanExecute = false;
            this.IsCanExecute = await Task.Run <bool>(() =>
            {
                try
                {
                    _viewModel.StatusString = String.Empty;
                    _viewModel.ResultString = String.Empty;
                    _viewModel.StatusString = String.Empty;

                    int i = 0;
                    string _folderName = Path.Combine(
                        Path.GetDirectoryName(_viewModel.FileName),
                        Path.GetFileNameWithoutExtension(_viewModel.FileName));

                    Directory.CreateDirectory(_folderName);

                    using (FileStream _input = new FileStream(_viewModel.FileName, FileMode.Open))
                    {
                        using (BinaryReader _br = new BinaryReader(_input))
                        {
                            while (_input.Position < _input.Length)
                            {
                                IStci _stci = StciLoader.LoadStci(_input);
                                i++;
                                string _fileName = Path.Combine(_folderName, i.ToString() + ".STI");
                                using (FileStream _output = new FileStream(_fileName, FileMode.Create))
                                {
                                    _stci.Save(_output);
                                }
                            }
                        }
                    }

                    _viewModel.StatusString = "Done";
                }
                catch (Exception exc)
                {
                    _viewModel.ErrorString = Common.GetErrorString(exc);
                }

                return(true);
            });
        }
Exemple #5
0
        private void FLoadSlfWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.IsBusy = true;
            try
            {
                string  _slfFileName = (string)e.Argument;
                SlfFile _slfFile     = new SlfFile(_slfFileName);
                _slfFile.LoadRecords();
                var _jsdRecords = _slfFile.Records.Where(x => x.FileNameExtention.ToLower() == ".jsd");
                int _recNum     = _jsdRecords.Count();
                foreach (SlfFile.Record _record in _jsdRecords)
                {
                    JsdFileViewModel _jsdFileViewModel = null;

                    MemoryStream _ms      = new MemoryStream(_record.Data);
                    JsdFile      _jsdFile = JsdFile.Load(_ms);
                    _ms.Close();

                    _jsdFileViewModel = new JsdFileViewModel(_jsdFile, _record.FileName);

                    SlfFile.Record _stiRecord = _slfFile.Records
                                                .Where(x => x.FileName.ToLower() == _record.FileName.ToLower().Replace(".jsd", ".sti"))
                                                .SingleOrDefault();

                    if (_stiRecord != null)
                    {
                        _ms = new MemoryStream(_stiRecord.Data);
                        IStci _stci = StciLoader.LoadStci(_ms);
                        if (_stci.IsIndexed)
                        {
                            _jsdFileViewModel.StciFile = (StciIndexed)_stci;
                        }
                    }

                    this.JsdFilesCount++;
                    this.FLoadSlfWorker.ReportProgress(100 * this.JsdFilesCount / _recNum, _jsdFileViewModel);
                }
            }
            finally
            {
                this.IsBusy = false;
            }
        }
        public async void Execute(object parameter)
        {
            TestViewModel _viewModel = (TestViewModel)parameter;
            DirectoryInfo _dir       = new DirectoryInfo(_viewModel.FolderName);

            this.IsCanExecute = false;
            this.IsCanExecute = await Task.Run <bool>(() =>
            {
                try
                {
                    _viewModel.StatusString = String.Empty;
                    _viewModel.ResultString = String.Empty;
                    _viewModel.StatusString = String.Empty;

                    FileInfo[] _files = _dir.GetFiles("*.STI", SearchOption.AllDirectories);

                    string _currentDir = String.Empty;
                    int _i             = 0;
                    foreach (FileInfo _file in _files)
                    {
                        StciLoader.ReloadStci(_file.FullName);

                        if (_currentDir != _file.DirectoryName)
                        {
                            _currentDir             = _file.DirectoryName;
                            _viewModel.StatusString = String.Format("{0} processing ...", _currentDir);
                            _viewModel.ResultString = String.Format("{0} folders processed", ++_i);
                        }
                    }

                    _viewModel.StatusString = "Done";
                }
                catch (Exception exc)
                {
                    _viewModel.ErrorString = Common.GetErrorString(exc);
                }

                return(true);
            });
        }
Exemple #7
0
        public JsdFileViewModel LoadJsdFile(string aFile)
        {
            FileStream _fs      = new FileStream(aFile, FileMode.Open);
            JsdFile    _jsdFile = JsdFile.Load(_fs);

            _fs.Close();

            string _fileName = String.Empty;

            if (this.FolderName != String.Empty)
            {
                _fileName = aFile.Replace(this.FolderName, String.Empty);
            }
            else
            {
                _fileName = Path.GetFileName(aFile);
            }

            JsdFileViewModel _jsdFileViewModel = new JsdFileViewModel(_jsdFile, _fileName);

            _jsdFileViewModel.FullFileName = aFile;

            string _stiFileName = Path.ChangeExtension(aFile, ".sti");

            if (File.Exists(_stiFileName))
            {
                _fs = new FileStream(_stiFileName, FileMode.Open);
                IStci _stci = StciLoader.LoadStci(_fs);
                _fs.Close();
                if (_stci.IsIndexed)
                {
                    _jsdFileViewModel.StciFile = (StciIndexed)_stci;
                }
            }
            return(_jsdFileViewModel);
        }
Exemple #8
0
        private ImageSource GetGlobalMapImagefFromSti(string aFileName)
        {
            string _path = Path.Combine(this.FGlobalMapsFolder, aFileName);
            IStci  _sti  = null;

            if (File.Exists(_path))
            {
                using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read))
                    _sti = StciLoader.LoadStci(input);
            }
            else
            {
                if (this.SlfFile != null)
                {
                    SlfFile.Record _record = this.SlfFile.Records
                                             .SingleOrDefault(x => x.FileName.ToUpperInvariant() == aFileName.ToUpperInvariant());
                    if (_record != null)
                    {
                        using (MemoryStream input = new MemoryStream(_record.Data))
                            _sti = StciLoader.LoadStci(input);
                    }
                }
            }

            if (_sti == null)
            {
                ImageSourceConverter _isc = new ImageSourceConverter();
                ImageSource          _is  = (ImageSource)_isc.ConvertFromString("MAP_STUB.bmp");
                return(_is);
            }
            else if (_sti is StciIndexed)
            {
                StciIndexed  _stciIndexed = (StciIndexed)_sti;
                List <Color> _palette     = _stciIndexed.ColorPalette
                                            .Select(x => new Color()
                {
                    A = 255, R = x.Red, G = x.Green, B = x.Blue
                })
                                            .ToList();

                StciSubImage   _subImage = _stciIndexed.Images[0];
                StructureImage _image    = new StructureImage(_subImage, _palette);
                BitmapPalette  _pb       = new BitmapPalette(_palette);
                PixelFormat    _pf       = PixelFormats.Indexed8;

                BitmapSource _bitmap = BitmapSource.Create(
                    _subImage.Header.Width,
                    _subImage.Header.Height,
                    96,
                    96,
                    _pf,
                    _pb,
                    _subImage.ImageData,
                    _subImage.Header.Width * _pf.BitsPerPixel / 8);
                return(_bitmap);
            }
            else if (_sti is StciRgb)
            {
                StciRgb     _stciRgb = (StciRgb)_sti;
                PixelFormat _pf      = PixelFormats.Bgr565;

                BitmapSource _bitmap = BitmapSource.Create(
                    _stciRgb.Header.ImageWidth,
                    _stciRgb.Header.ImageHeight,
                    96,
                    96,
                    _pf,
                    null,
                    _stciRgb.ImageData,
                    _stciRgb.Header.ImageWidth * _pf.BitsPerPixel / 8);
                return(_bitmap);
            }

            return(null);
        }
Exemple #9
0
        public void LoadMapTileSet(Map aMap)
        {
            for (int k = 0; k < TileSet.NumOfTileTypes; k++)
            {
                string _fileName  = TileSet.TileSets[aMap.TilesetID].TileSurfaceFilenames[k];
                int    _tilesetId = aMap.TilesetID;
                if (_fileName == String.Empty)
                {
                    _fileName  = TileSet.TileSets[0].TileSurfaceFilenames[k];
                    _tilesetId = 0;
                }

                _fileName = Path.Combine(_tilesetId.ToString(), _fileName);

                string      _path = Path.Combine(this.FTilesetFolder, _fileName);
                StciIndexed _sti  = null;
                if (File.Exists(_path))
                {
                    //using(FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read))
                    _sti = (StciIndexed)StciLoader.LoadStci(_path);
                }
                else
                {
                    if (File.Exists(this.FTilesetFileName))
                    {
                        SlfFile.Record _record = this.TilesetSlfFile.Records
                                                 .SingleOrDefault(x => x.State == 0 && x.FileName.ToUpperInvariant() == _fileName.ToUpperInvariant());
                        if (_record != null)
                        {
                            using (MemoryStream input = new MemoryStream(_record.Data))
                                _sti = (StciIndexed)StciLoader.LoadStci(input, _fileName);
                        }
                        else
                        {
                            throw new FileNotFoundException(
                                      String.Format("Record {0} is not found in file {1}.", _fileName, this.FTilesetFileName));
                        }
                    }
                    else
                    {
                        throw new FileNotFoundException(
                                  String.Format("Files {0}, {1} are not found.", _path, this.FTilesetFileName));
                    }
                }

                JsdFile _jsd = null;
                _path = Path.ChangeExtension(_path, ".jsd");
                if (File.Exists(_path))
                {
                    using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read))
                    {
                        _jsd = JsdFile.Load(input);
                    }
                }
                else
                {
                    if (File.Exists(this.FTilesetFileName))
                    {
                        _fileName = Path.ChangeExtension(_fileName, "jsd");
                        SlfFile.Record _record = this.TilesetSlfFile.Records
                                                 .SingleOrDefault(x => x.FileName.ToUpperInvariant() == _fileName.ToUpperInvariant());
                        if (_record != null)
                        {
                            using (MemoryStream input = new MemoryStream(_record.Data))
                                _jsd = JsdFile.Load(input);
                        }
                        //else
                        //{
                        //    throw new FileNotFoundException(
                        //        String.Format("Record {0} is not found in file {1}.", _fileName, this.FTilesetFileName));
                        //}
                    }
                    //else
                    //{
                    //    throw new FileNotFoundException(
                    //        String.Format("Files {0}, {1} are not found.", _path, this.FTilesetFileName));
                    //}
                }

                aMap.MapTileSet[k] = new Map.TileObject(_sti, _jsd);
            }
        }