Beispiel #1
0
        private static bool ValidateOptions(DistillSettings Settings)
        {
            if (Settings.FileGroups == null || Settings.KnownPlatforms == null || Settings.TagSets == null)
            {
                Error("Failed to load configuration file");
                return(false);
            }

            // Fix the case of the platform
            foreach (PlatformInfo Platform in Settings.KnownPlatforms)
            {
                if (Platform.Name.ToUpper() == Options.Platform.ToUpper())
                {
                    Options.Platform = Platform.Name;
                    break;
                }
            }

            if ((Options.bAuthenticate || Options.bVerify) && !Options.bChecksum)
            {
                Warning(" ... enabling checksums (-c) to allow verification and authentication");
                Options.bChecksum = true;
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>Get the tagset to use to define the set of files to operate on</summary>
        /// <param name="Settings">The contents of the configuration file</param>
        /// <returns>The tagset that defines which files to operate on</returns>
        public static TagSet GetTagSet(DistillSettings Settings)
        {
            TagSet Tags =
                (
                    from TagSetDetail in Settings.TagSets
                    where TagSetDetail.Name == Options.TagSet
                    select TagSetDetail
                ).FirstOrDefault();

            if (Tags == null)
            {
                Error("Failed to find tagset: " + Options.TagSet);
                return(null);
            }

            Log(" ... using tagset " + Tags.Name + " with " + Tags.Tags.Length + " tags.", ConsoleColor.Cyan);
            return(Tags);
        }
Beispiel #3
0
		/// <summary>Gets the list of filesets with macros from the configuration file</summary>
		/// <param name="Settings">The contents of the configuration file</param>
		/// <param name="Set">The tagset to look for</param>
		/// <returns>A list of filesets including macros</returns>
		public static List<FileSet> GetFileSets( DistillSettings Settings, TagSet Set )
		{
			IEnumerable<FileSet[]> BaseSets =
			(
				from Group in Settings.FileGroups
				where Set.Tags.Contains( Group.Tag )
				where Group.Platform == null || Group.Platform.Contains( Options.Platform )
				select Group.Files
			);

			List<FileSet> Sets = new List<FileSet>();
			foreach( FileSet[] FileSet in BaseSets )
			{
				Sets.AddRange( FileSet );
			}

			return Sets;
		}
Beispiel #4
0
		/// <summary>Get the tagset to use to define the set of files to operate on</summary>
		/// <param name="Settings">The contents of the configuration file</param>
		/// <returns>The tagset that defines which files to operate on</returns>
		public static TagSet GetTagSet( DistillSettings Settings )
		{
			TagSet Tags =
			(
				from TagSetDetail in Settings.TagSets
				where TagSetDetail.Name == Options.TagSet
				select TagSetDetail
			).FirstOrDefault();

			if( Tags == null )
			{
				Error( "Failed to find tagset: " + Options.TagSet );
				return null;
			}

			Log( " ... using tagset " + Tags.Name + " with " + Tags.Tags.Length + " tags.", ConsoleColor.Cyan );
			return Tags;
		}
Beispiel #5
0
        /// <summary>Gets the list of filesets with macros from the configuration file</summary>
        /// <param name="Settings">The contents of the configuration file</param>
        /// <param name="Set">The tagset to look for</param>
        /// <returns>A list of filesets including macros</returns>
        public static List <FileSet> GetFileSets(DistillSettings Settings, TagSet Set)
        {
            IEnumerable <FileSet[]> BaseSets =
                (
                    from Group in Settings.FileGroups
                    where Set.Tags.Contains(Group.Tag)
                    where Group.Platform == null || Group.Platform.Contains(Options.Platform)
                    select Group.Files
                );

            List <FileSet> Sets = new List <FileSet>();

            foreach (FileSet[] FileSet in BaseSets)
            {
                Sets.AddRange(FileSet);
            }

            return(Sets);
        }
Beispiel #6
0
        /// <summary>Generate a new list of filesets with all macros (e.g. %GAME%) expanded to their real values</summary>
        /// <param name="FileSets">List of filesets potentially containing macros</param>
        /// <param name="Settings">The settings used to fill in the macros</param>
        /// <returns>List of filesets with evaluated macros</returns>
        public static List <FileSet> ExpandMacros(List <FileSet> FileSets, DistillSettings Settings)
        {
            List <FileSet> NewFileSets = new List <FileSet>();

            Options.NotPlatforms = new List <string>(Settings.KnownPlatforms.Where(x => x.Name != Options.Platform && !Options.IncPlatforms.Contains(x.Name)).Select(x => x.Name));
            Options.NotLanguages = new List <string>(Settings.KnownLanguages.Where(x => x != Options.Region));

            foreach (FileSet OldFileSet in FileSets)
            {
                FileSet NewFileSet = new FileSet();

                NewFileSet.bIsRecursive = OldFileSet.bIsRecursive;
                NewFileSet.Path         = OldFileSet.Path;

                NewFileSet.Path = NewFileSet.Path.Replace("%GAME%", Options.Game);
                NewFileSet.Path = NewFileSet.Path.Replace("%PLATFORM%", Options.Platform);
                NewFileSet.Path = NewFileSet.Path.Replace("%LANGUAGE%", Options.Region);
                NewFileSet.Path = NewFileSet.Path.Replace("\\", "/");

                NewFileSet.FilterOutFiles   = ExpandFilterMacros(OldFileSet.FilterOutFiles);
                NewFileSet.FilterOutFolders = ExpandFilterMacros(OldFileSet.FilterOutFolders);

                if (NewFileSet.FilterOutFolders != null)
                {
                    List <string> NewFolders = new List <string>();
                    foreach (string FilterOutFolder in NewFileSet.FilterOutFolders)
                    {
                        string NewFilter = "/" + FilterOutFolder + "/";
                        NewFolders.Add(NewFilter);
                    }
                    NewFileSet.FilterOutFolders = NewFolders.ToArray();
                }

                NewFileSets.Add(NewFileSet);
            }

            Log(" ... found " + NewFileSets.Count + " file sets.", ConsoleColor.Cyan);
            return(NewFileSets);
        }
        /// <summary>Generate a new list of filesets with all macros (e.g. %GAME%) expanded to their real values</summary>
        /// <param name="FileSets">List of filesets potentially containing macros</param>
        /// <param name="Settings">The settings used to fill in the macros</param>
        /// <returns>List of filesets with evaluated macros</returns>
        public static List<FileSet> ExpandMacros( List<FileSet> FileSets, DistillSettings Settings )
        {
            List<FileSet> NewFileSets = new List<FileSet>();

            Options.NotPlatforms = new List<string>( Settings.KnownPlatforms.Where( x => x.Name != Options.Platform && !Options.IncPlatforms.Contains(x.Name) ).Select( x => x.Name ) );
            Options.NotLanguages = new List<string>( Settings.KnownLanguages.Where( x => x != Options.Region ) );

            foreach( FileSet OldFileSet in FileSets )
            {
                FileSet NewFileSet = new FileSet();

                NewFileSet.bIsRecursive = OldFileSet.bIsRecursive;
                NewFileSet.Path = OldFileSet.Path;

                NewFileSet.Path = NewFileSet.Path.Replace( "%GAME%", Options.Game );
                NewFileSet.Path = NewFileSet.Path.Replace( "%PLATFORM%", Options.Platform );
                NewFileSet.Path = NewFileSet.Path.Replace( "%LANGUAGE%", Options.Region );
                NewFileSet.Path = NewFileSet.Path.Replace( "\\", "/" );

                NewFileSet.FilterOutFiles = ExpandFilterMacros(OldFileSet.FilterOutFiles);
                NewFileSet.FilterOutFolders = ExpandFilterMacros(OldFileSet.FilterOutFolders);

                if (NewFileSet.FilterOutFolders != null)
                {
                    List<string> NewFolders = new List<string>();
                    foreach (string FilterOutFolder in NewFileSet.FilterOutFolders)
                    {
                        string NewFilter = "/" + FilterOutFolder + "/";
                        NewFolders.Add(NewFilter);
                    }
                    NewFileSet.FilterOutFolders = NewFolders.ToArray();
                }

                NewFileSets.Add( NewFileSet );
            }

            Log( " ... found " + NewFileSets.Count + " file sets.", ConsoleColor.Cyan );
            return NewFileSets;
        }
Beispiel #8
0
        /// <summary>The main entry point of the program</summary>
        /// <param name="Arguments">The arguments passed on on the commandline</param>
        /// <returns>Zero on success, non zero for failure</returns>
        private static int Main(string[] Arguments)
        {
            if (Arguments.Length == 0)
            {
                ShowUsage();
                return(1);
            }

            // Set the current directory to the root of the branch
            Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, "..", "..", "..");
            Options.Source      = Environment.CurrentDirectory;
            Options.Destination = Environment.CurrentDirectory;

            // Remember console color for restoring on exit
            ConsoleColor OriginalConsoleColor = Console.ForegroundColor;

            // Parse the command line for settings
            ParseArguments(Arguments);

            // Load the Distill.xml file and the game specific version
            string SettingsLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Options.DistillSettings);

            if (File.Exists(SettingsLocation) == false)
            {
                Error("Unable to find distill file " + Options.DistillSettings);
                Console.ForegroundColor = OriginalConsoleColor;
                return(-1);
            }

            DistillSettings Settings = XmlHandler.ReadXml <DistillSettings>(SettingsLocation);

            // Find the known languages based on the folders in Engine Localization
            Settings.KnownLanguages = FindKnownLanguages();

            // Ensure the settings are valid
            if (!ValidateOptions(Settings))
            {
                Console.ForegroundColor = OriginalConsoleColor;
                return(-1);
            }

            // Get the set of tags we wish to copy
            TagSet Set = GetTagSet(Settings);

            if (Set == null)
            {
                Console.ForegroundColor = OriginalConsoleColor;
                return(-1);
            }

            // Get a list of filesets that includes all the unexpanded macros
            List <FileSet> DecoratedFileSets = GetFileSets(Settings, Set);

            if (DecoratedFileSets.Count == 0)
            {
                Error("No file sets for game, platform, tagset combination!");
                Console.ForegroundColor = OriginalConsoleColor;
                return(-1);
            }

            // Expand out all the macros
            List <FileSet> FileSets = ExpandMacros(DecoratedFileSets, Settings);
            // Get the files referenced by the filesets
            List <FileInfo> Files = GetFiles(FileSets);
            // Create a TOC
            TOC TableOfContents = new TOC(Files);

            Files = null;

            if (Options.bAuthenticate)
            {
                // If we're authenticating, compare the newly created TOC from files with the existing one on disk
                Authenticate(TableOfContents);
            }
            else
            {
                // Only write a TOC if we're copying locally to somewhere else (the most common case)
                string TOCFileName = Path.Combine(Options.Source, Options.Game, "TOC.xml");
                if (Options.bTOC && (Options.Source == Environment.CurrentDirectory))
                {
                    Log(" ... writing TOC: " + TOCFileName, ConsoleColor.Cyan);
                    XmlHandler.WriteXml <TOC>(TableOfContents, TOCFileName, "");
                }

                // Copy the TOC if it exists
                if (Options.bTOC)
                {
                    FileInfo TOCFileInfo = new FileInfo(TOCFileName);
                    if (TOCFileInfo.Exists)
                    {
                        TableOfContents.Entries.Add(new TOCEntry(TOCFileInfo));
                    }
                    else
                    {
                        Error(" ... Expected a TOC but there isn't one to copy: " + TOCFileName);
                    }
                }

                // Copy files
                ZipFiles(TableOfContents);
                CopyFiles(TableOfContents);
                FTPFiles(TableOfContents);

                Log("Distill process successful!", ConsoleColor.Green);
            }

            // Restore console color
            Console.ForegroundColor = OriginalConsoleColor;
            return(ErrorCode);
        }
Beispiel #9
0
        private static bool ValidateOptions( DistillSettings Settings )
        {
            if( Settings.FileGroups == null || Settings.KnownPlatforms == null || Settings.TagSets == null )
            {
                Error( "Failed to load configuration file" );
                return false;
            }

            // Fix the case of the platform
            foreach( PlatformInfo Platform in Settings.KnownPlatforms )
            {
                if( Platform.Name.ToUpper() == Options.Platform.ToUpper() )
                {
                    Options.Platform = Platform.Name;
                    break;
                }
            }

            if( ( Options.bAuthenticate || Options.bVerify ) && !Options.bChecksum )
            {
                Warning( " ... enabling checksums (-c) to allow verification and authentication" );
                Options.bChecksum = true;
            }

            return true;
        }