Пример #1
0
        private static PartSet findParts(DirectoryInfo saveFolder, PartSet library)
        {
            var saveFile = new FileInfo(Strut.String.combinePath(saveFolder.FullName, "persistent.sfs"));

            if (!saveFile.Exists)
            {
                throw new Strut.MissingFileException(saveFile);
            }
            return(Part.parseFromSfs(saveFile, library));
        }
Пример #2
0
        public static SaveGame create(DirectoryInfo location, PartSet library)
        {
            if (!location.Exists)
            {
                throw new Strut.MissingFolderException(location);
            }
            var game = new SaveGame(location);

            game.parts_.UnionWith(findParts(game.location_, library));
            return(game);
        }
Пример #3
0
        // Note: expensive call
        private static PartSet findPartsIn(params DirectoryInfo[] folders)
        {
            var result = new PartSet();

            foreach (var folder in folders)
            {
                foreach (var partFile in folder.EnumerateFiles(partFileNameGlob_, SearchOption.AllDirectories))
                {
                    result.UnionWith(Part.parseFromCfg(partFile));
                }
            }
            return(result);
        }
Пример #4
0
        public static PartSet parseFromSfs( FileInfo saveFile, PartSet library )
        {
            if ( !saveFile.Exists )
                throw new Strut.MissingFileException( saveFile );

            var state = ParseState.LookingForPart;
            var result = new PartSet();
            // TODO: catch IO exceptions
            using ( var reader = new StreamReader( saveFile.FullName ) ) {
                string line;
                while ( ( line = reader.ReadLine() ) != null ) {
                    switch ( state ) {
                        case ParseState.LookingForPart:
                            if ( partRegex_.IsMatch( line ) )
                                state = ParseState.LookingForName;
                            break;

                        case ParseState.LookingForName:
                            if ( nameRegex_.IsMatch( line ) ) {
                                var match = nameRegex_.Match( line );
                                var partName = match.Groups ["name"].Value;
                                try {
                                    if ( !skipParts_.Contains( partName ) )
                                        result.Add( library.First( part => part.loadedName.Equals( partName ) ) );
                                }
                                catch ( Exception ex ) {
                                    Console.WriteLine(
                                        ">>> Save '{0}' uses part '{1}' that is not in install: {2}",
                                        saveFile.FullName,
                                        partName,
                                        ex.Message );
                                }
                                state = ParseState.LookingForPart;
                            }
                            break;
                    }
                }
            }
            return result;
        }