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; this.IsCanExecute = false; this.IsCanExecute = await Task.Run <bool>(() => { try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; using (FileStream _fs = new FileStream(_viewModel.FileName, FileMode.Open)) { JsdFile _jsd = JsdFile.Load(_fs); _viewModel.ResultString += _jsd.ToString(); foreach (JsdStruct _struct in _jsd.Structs) { _struct.Rotate(true); } _viewModel.ResultString += "==================================================="; _viewModel.ResultString += _jsd.ToString(); } _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }
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); }
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); } }