Beispiel #1
0
        public PlayerProfileData ImportDynamicDatabase(string importFilePath)
        {
            if (!File.Exists(importFilePath))
            {
                Debug.LogError("Cannot find database file for import: " + importFilePath);
                return(null);
            }

            // Copy the file
            string fileName    = Path.GetFileName(importFilePath);
            string newFilePath = DBService.GetDatabaseFilePath(fileName, AppConfig.DbPlayersFolder);

            /* @note: we overwrite it
             *  if (File.Exists(newFilePath)) {
             *  Debug.LogError("Database already exists. Cannot import: " + importFilePath);
             *  return null;
             * }*/

            File.Copy(importFilePath, newFilePath, true);

            // Load the new DB and get its player profile data
            var importDbService   = DBService.OpenFromFilePath(false, newFilePath);
            var playerProfileData = importDbService.GetPlayerProfileData();

            importDbService.CloseConnection();
            return(playerProfileData);
        }
Beispiel #2
0
        /// <summary>
        /// Exports the players joined db reading them from the import directory
        /// </summary>
        /// <returns><c>true</c>, if players joined db was exported, <c>false</c> otherwise.</returns>
        /// <param name="errorString">Error string.</param>
        public bool ExportPlayersJoinedDb(out string errorString)
        {
            // Load all the databases we can find and get the player UUIDs
            var allUUIDs  = new List <string>();
            var filePaths = GetImportFilePaths();

            if (filePaths != null)
            {
                foreach (var filePath in filePaths)
                {
                    // Check whether that is a DB and load it
                    if (IsValidDatabasePath(filePath))
                    {
                        var importDbService   = DBService.OpenFromFilePath(false, filePath);
                        var playerProfileData = importDbService.GetPlayerProfileData();
                        if (playerProfileData == null)
                        {
                            // skip no-player DBs, they are wrong
                            continue;
                        }
                        allUUIDs.Add(playerProfileData.Uuid);
                        importDbService.CloseConnection();
                    }
                }
            }
            else
            {
                errorString = "Could not find the import folder: " + AppConfig.DbImportFolder;
                Debug.LogError(errorString);
                return(false);
            }

            // Create the joined DB
            var joinedDbService = DBService.OpenFromDirectoryAndFilename(true, AppConfig.GetJoinedDatabaseFilename(), AppConfig.DbJoinedFolder);

            InjectStaticData(joinedDbService);
            InjectEnums(joinedDbService);

            // Export and inject all the DBs
            foreach (var uuid in allUUIDs)
            {
                // Export
                var exportDbService = DBService.ExportFromPlayerUUIDAndReopen(uuid, dirName: AppConfig.DbImportFolder);
                InjectUUID(uuid, exportDbService);

                // Inject
                InjectExportedDB(uuid, exportDbService, joinedDbService);
                exportDbService.CloseConnection();
                exportDbService.ForceFileDeletion();
            }

            joinedDbService.CloseConnection();
            errorString = "";
            return(true);
        }