Exemple #1
0
        public static SlfFile Create(DirectoryInfo aDir, string aSearchPattern, SearchOption aSearchOptions)
        {
            FileInfo[] _files = aDir.GetFiles(aSearchPattern, aSearchOptions);
            if (_files == null || _files.Length == 0)
            {
                return(null);
            }

            SlfFile.Header FHeader = new Header();
            FHeader.LibName = String.Format("{0}.SLF", aDir.Name);

            if (aSearchOptions == SearchOption.AllDirectories)
            {
                FHeader.PathToLibrary = String.Format("{0}\\", aDir.Name);
            }
            else
            {
                FHeader.PathToLibrary = String.Empty;
            }

            FHeader.iEntries = _files.Length;
            FHeader.iUsed    = _files.Length;
            FHeader.iSort    = -1;
            FHeader.iVersion = 512;

            DirectoryInfo[] _subDirs = aDir.GetDirectories();

            FHeader.fContainsSubDirectories = (byte)(_subDirs.Length > 0 ? 1 : 0);

            int _dirLength = aDir.FullName.Length + 1;

            SlfFile.Record[] _records = new SlfFile.Record[_files.Length];
            SlfFile.Record[] FRecords = new SlfFile.Record[FHeader.iEntries];
            for (int i = 0; i < _files.Length; i++)
            {
                FileInfo _file = _files[i];

                SlfFile.Record.Header _recHeader = new Record.Header();
                _recHeader.FileName = _file.FullName.Substring(_dirLength);
                _recHeader.FileTime = _file.CreationTimeUtc;
                _recHeader.uiLength = (uint)_file.Length;
                SlfFile.Record _rec = new Record(_recHeader);

                using (FileStream _fs = new FileStream(_file.FullName, FileMode.Open))
                {
                    _rec.LoadData(_fs);
                }

                FRecords[i] = _rec;
                string _key = _rec.FileName;
                if (_rec.State != FileOk)
                {
                    _key = String.Format("{0}_{1}", _rec.FileName, _rec.State);
                }
            }

            SlfFile _slf = new SlfFile(FHeader, FRecords);

            return(_slf);
        }
Exemple #2
0
        public void Load()
        {
            if (File.Exists(this.FFileName))
            {
                using (FileStream _fs = new FileStream(this.FFileName, FileMode.Open))
                {
                    this.Load(_fs);
                }
            }
            else
            {
                string _mapsFolder  = Path.GetDirectoryName(this.FFileName);
                string _dataFolder  = Path.GetDirectoryName(_mapsFolder);
                string _mapsSlfFile = Path.Combine(_dataFolder, "Maps.slf");
                if (File.Exists(_mapsSlfFile))
                {
                    SlfFile _mapsSlf = new SlfFile(_mapsSlfFile);
                    _mapsSlf.LoadRecords();
                    string _mapName = Path.GetFileName(this.FFileName);
                    //SlfFile.Record _record = _mapsSlf.Records.
                    //    SingleOrDefault(x => x.FileName.ToUpperInvariant() == _mapName.ToUpperInvariant());
                    SlfFile.Record _record = null;
                    foreach (SlfFile.Record _rec in _mapsSlf.Records)
                    {
                        if (_rec.FileName.ToUpperInvariant() == _mapName.ToUpperInvariant())
                        {
                            _record = _rec;
                            break;
                        }
                    }

                    if (_record != null)
                    {
                        using (MemoryStream _ms = new MemoryStream(_record.Data))
                        {
                            this.Load(_ms);
                        }
                    }
                    else
                    {
                        throw new FileNotFoundException(
                                  String.Format("Record {0} is not found in file {1}", _mapName, _mapsSlfFile));
                    }
                }
                else
                {
                    throw new FileNotFoundException(
                              String.Format("Files {0}, {1} are not found.", this.FFileName, _mapsSlfFile));
                }
            }
        }
Exemple #3
0
 public static SlfFile Create(DirectoryInfo aDir, SearchOption aSearchOptions)
 {
     return(SlfFile.Create(aDir, "*.*", aSearchOptions));
 }