示例#1
0
        /// <summary>
        /// Handles prompting user for choosing a file and then handles opening it.
        /// </summary>
        /// <param name="path"></param>
        public void OpenModule(string path)
        {
            WinterConnectionInformation.ActiveModuleDirectoryPath = path;
            ModulePath = path;

            using(FileArchiveManager manager = new FileArchiveManager())
            {
                TemporaryDirectoryPath = manager.CreateUniqueDirectory();
                // Extract all files contained in the module zip file to the temporary directory.
                manager.ExtractArchive(ModulePath, TemporaryDirectoryPath);
            }

            FileHelper fileHelper = new FileHelper();
            string databaseFilePath = fileHelper.GetDatabaseFileInDirectory(TemporaryDirectoryPath);

            // Change the database connection to the file located in the extracted module folder.
            using (DatabaseRepository repo = new DatabaseRepository())
            {
                repo.ChangeDatabaseConnection(databaseFilePath);
            }

            CheckForMissingContentPackages();
        }
示例#2
0
        /// <summary>
        /// Creates a new module in the temporary directory.
        /// Note that this module will not become permanent until a call to SaveModule() is made.
        /// </summary>
        /// <returns>True if successful, false if unsuccessful</returns>
        public bool CreateModule()
        {
            try
            {
                using (FileArchiveManager manager = new FileArchiveManager())
                {
                    TemporaryDirectoryPath = manager.CreateUniqueDirectory();
                }

                // Build a new database file and structure.
                using (DatabaseRepository repo = new DatabaseRepository())
                {
                    repo.CreateNewDatabase(TemporaryDirectoryPath, "WinterEngineDB", true);
                }

                EntityCreationScripts creationScripts = new EntityCreationScripts();
                creationScripts.Initialize();

                // Add the module details to the correct table.
                using (GameModuleRepository repo = new GameModuleRepository())
                {
                    GameObjectFactory factory = new GameObjectFactory();
                    GameModule module = factory.CreateObject(GameObjectTypeEnum.GameModule, ModuleName, ModuleTag, ModuleResref) as GameModule;

                    repo.Add(module);
                }

                LoadSystemContentPacks();

                return true;
            }
            catch(Exception ex)
            {
                throw new Exception("Error creating module.", ex);
            }
        }