Пример #1
0
        /// <summary>
        /// Patch the current Database. Optionally save.
        /// </summary>
        /// <param name="saveFolder">The working directory of the Controller. Set to null for default handling.</param>
        /// <returns>The Generic Importer and the Controller.</returns>
        /// <exception cref="Exception">This method may throw based on the Initialisation method.</exception>
        public static void GenerateDatabasePatch(
            string patchFile,
            string?saveFolder = null)
        {
            Console.WriteLine($"GenerateDatabasePatch called with patchFile={patchFile}, saveFolder={saveFolder}...");

            if (saveFolder == null)
            {
                saveFolder = Directory.GetParent(patchFile).FullName;
            }

            try
            {
                WinApi.TryTimeBeginPeriod(1);
                Directory.CreateDirectory(saveFolder);

                // Load.
                SplatTagJsonSnapshotDatabase splatTagJsonSnapshotDatabase = new SplatTagJsonSnapshotDatabase(saveFolder);
                GenericFilesToIImporters     iImporters = new GenericFilesToIImporters(saveFolder, patchFile);
                MultiDatabase database = new MultiDatabase()
                                         .With(splatTagJsonSnapshotDatabase)
                                         .With(iImporters);

                SplatTagController splatTagController = new SplatTagController(database);
                splatTagController.Initialise();

                // Now that we've initialised, take a snapshot of everything.
                SaveDatabase(splatTagController, splatTagJsonSnapshotDatabase);
            }
            finally
            {
                WinApi.TryTimeEndPeriod(1);
            }
        }
Пример #2
0
        /// <summary>
        /// Generate a new Database. Optionally save.
        /// </summary>
        /// <param name="saveFolder">The working directory of the Controller. Set to null for default handling.</param>
        /// <returns>The Generic Importer and the Controller.</returns>
        /// <exception cref="Exception">This method may throw based on the Initialisation method.</exception>
        public static (GenericFilesToIImporters, SplatTagController) GenerateNewDatabase(
            string?saveFolder  = null,
            string?sourcesFile = null)
        {
            Console.WriteLine($"GenerateNewDatabase called with saveFolder={saveFolder}, sourcesFile={sourcesFile}...");

            if (sourcesFile == null)
            {
                sourcesFile = GenericFilesToIImporters.DefaultSourcesFileName;

                if (saveFolder == null)
                {
                    saveFolder = GetDefaultPath();
                }
            }
            else if (saveFolder == null)
            {
                saveFolder = Directory.GetParent(sourcesFile).FullName;
            }

            try
            {
                WinApi.TryTimeBeginPeriod(1);

                // Directories created in GenericFilesToIImporters
                GenericFilesToIImporters sourcesImporter    = new GenericFilesToIImporters(saveFolder, sourcesFile);
                MultiDatabase            splatTagDatabase   = new MultiDatabase().With(sourcesImporter);
                SplatTagController       splatTagController = new SplatTagController(splatTagDatabase);
                Console.WriteLine($"Full load of {sourcesImporter.Sources.Count} files from dir {Path.GetFullPath(saveFolder)}...");
                splatTagController.Initialise();

                // Now that we've initialised, take a snapshot of everything.
                SaveDatabase(splatTagController, saveFolder);
                return(sourcesImporter, splatTagController);
            }
            finally
            {
                WinApi.TryTimeEndPeriod(1);
            }
        }