public async void Execute(object parameter) { TestViewModel _viewModel = (TestViewModel)parameter; DirectoryInfo _dir = new DirectoryInfo(_viewModel.FolderName); this.CanExecuteProperty = false; this.CanExecuteProperty = await Task.Run <bool>(() => { try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; _viewModel.StatusString = String.Empty; SlfFile _slf = SlfFile.Create(_dir, SearchOption.AllDirectories); if (_slf != null) { string _fileName = String.Format("{0}.SLF", _dir.Name); string _fullFileName = Path.Combine(_dir.Parent.FullName, _fileName); _slf.Save(_fullFileName); } _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }
public async void Execute(object parameter) { SlfTestViewModel _viewModel = (SlfTestViewModel)parameter; this.IsCanExecute = false; this.IsCanExecute = await Task.Run <bool>(() => { try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; _viewModel.StatusString = String.Empty; int _filesCount = 0; SlfFile _slf = new SlfFile(_viewModel.FileName); int _fileCount = _slf.Extract(false); _filesCount += _fileCount; _viewModel.ResultString = String.Format( "{0} files extract", _filesCount); _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }
public async void Execute(object parameter) { SlfTestViewModel _viewModel = (SlfTestViewModel)parameter; DirectoryInfo _dir = new DirectoryInfo(_viewModel.FolderName); this.CanExecuteProperty = false; this.CanExecuteProperty = await Task.Run <bool>(() => { try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; _viewModel.StatusString = String.Empty; int _count = 0; foreach (FileInfo _file in _dir.GetFiles("*.SLF")) { SlfFile _slf = new SlfFile(_file.FullName); _viewModel.StatusString = String.Format("{0} processing ...", _file.Name); _slf.LoadRecords(); _slf.Save(); _viewModel.ResultString = String.Format("{0} files processed.", ++_count); } _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }
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; int _count = 0; StringBuilder _sb = new StringBuilder(); SlfFile _slf = SlfFile.Create(_dir, this.FSearchPattern, SearchOption.TopDirectoryOnly); if (_slf != null) { string _fileName = String.Format("{0}.SLF", _dir.Name); string _fullFileName = Path.Combine(_dir.FullName, _fileName); _slf.Save(_fullFileName); } foreach (DirectoryInfo _subDir in _dir.GetDirectories()) { _viewModel.StatusString = String.Format("{0} processing ...", _subDir.Name); _slf = SlfFile.Create(_subDir, this.FSearchPattern, SearchOption.AllDirectories); if (_slf != null) { string _fileName = String.Format("{0}.SLF", _subDir.Name); string _fullFileName = Path.Combine(_subDir.Parent.FullName, _fileName); _slf.Save(_fullFileName); } _viewModel.ResultString = String.Format( "{0} directories processed.", ++_count); } _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }
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; } }
private void LoadTileSet() { string _ja2SetData = System.IO.Path.Combine(this.DataFolder, @"BinaryData\JA2SET.DAT"); if (File.Exists(_ja2SetData)) { using (Stream _fs = new FileStream(_ja2SetData, FileMode.Open, FileAccess.Read)) { TileSet.Load(_fs); } } else { string _binaryDataFile = Path.Combine(this.DataFolder, "Binarydata.slf"); if (File.Exists(_binaryDataFile)) { SlfFile _binaryDataSlf = new SlfFile(_binaryDataFile); _binaryDataSlf.LoadRecords(); SlfFile.Record _ja2set = _binaryDataSlf.Records.SingleOrDefault(x => x.FileName.ToUpperInvariant() == "JA2SET.DAT"); if (_ja2set != null) { using (MemoryStream _ms = new MemoryStream(_ja2set.Data)) { TileSet.Load(_ms); } } else { throw new FileNotFoundException( String.Format("Record JA2SET.DAT is not found in file {0}.", _binaryDataFile)); } } else { throw new FileNotFoundException( String.Format("Files {0}, {1} are not found.", _ja2SetData, _binaryDataFile)); } } }