示例#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>
        /// Saves the module using a new path.
        /// </summary>
        /// <param name="path"></param>
        public void SaveModule(string path)
        {
            using (FileArchiveManager manager = new FileArchiveManager())
            {
                // Update the path to the module file
                if (!String.IsNullOrEmpty(path))
                {
                    ModulePath = path;
                }
                string backupPath = manager.GenerateUniqueFileName(ModulePath);

                // Make a back up of the module file just in case something goes wrong.
                if (File.Exists(ModulePath))
                {
                    File.Copy(ModulePath, backupPath);
                }

                File.Delete(ModulePath);
                manager.ArchiveDirectory(TemporaryDirectoryPath, ModulePath);

                // Delete the backup since the new save was successful.
                File.Delete(backupPath);
            }
        }
示例#3
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);
            }
        }