Esempio n. 1
0
        /// <summary>
        /// Reloads the database.
        /// </summary>
        /// <param name="progress">The progress object.</param>
        public void Reload(IProgress progress)
        {
            DbDebugHelper.OnUpdate("Reloading database...");
            OnPreviewReloaded();

            try {
                IOHelper.SetupFileManager();
                Commands.ClearCommands();
                DbPathLocator.ClearStoredFiles();
                ResetAllSettings();

                var dbs = _dbs.Values.ToList();

                for (int i = 0; i < dbs.Count; i++)
                {
                    dbs[i].Clear();
                    DbDebugHelper.OnCleared(dbs[i].DbSource, null, dbs[i]);
                }

                DbDebugHelper.OnUpdate("All database tables have been cleared.");

                for (int i = 0; i < dbs.Count; i++)
                {
                    var db = dbs[i];

                    if (db.CanBeLoaded)
                    {
                        CLHelper.CStart(i);

                        db.LoadDb();

                        if (progress != null)
                        {
                            progress.Progress = (i + 1f) / dbs.Count * 100f;
                            //ErrorHandler.HandleException("Now at " + progress.Progress + "% done.");
                        }

                        CLHelper.CStopAndDisplay(db.DbSource.DisplayName, i);
                    }

                    if (progress != null)
                    {
                        AProgress.IsCancelling(progress);
                    }
                }

                ClearCommands();
            }
            finally {
                DbDebugHelper.OnUpdate("Database reloaded...");
            }

            OnReloaded();
            SdeEditor.Instance.Dispatch(p => p.OnSelectionChanged());
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the database.
        /// </summary>
        /// <param name="ap">The progress object.</param>
        /// <param name="progress"> </param>
        public virtual void Save(AsyncOperation ap, IProgress progress)
        {
            string     dbPath     = GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath);
            string     subPath    = ProjectConfiguration.DatabasePath.Replace(dbPath, "").TrimStart('\\', '/');
            ServerType serverType = DbPathLocator.GetServerType();

            DbDebugHelper.OnUpdate("Saving tables.");

            MetaGrf.Clear();

            try {
                BackupEngine.Instance.Start(ProjectConfiguration.DatabasePath);

                var dbs = _dbs.Values.ToList();

                IOHelper.SetupFileManager();

                for (int i = 0; i < dbs.Count; i++)
                {
                    var db = dbs[i];
                    db.WriteDb(dbPath, subPath, serverType);

                    if (progress != null)
                    {
                        progress.Progress = AProgress.LimitProgress((i + 1f) / dbs.Count * 100f);
                    }
                }

                foreach (var db in dbs)
                {
                    db.SaveCommandIndex();
                }

                Commands.SaveCommandIndex();
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
            finally {
                if (ap != null && progress != null)
                {
                    progress.Progress = ap.ProgressBar.GetIntermediateState("Backup manager");
                }

                BackupEngine.Instance.Stop();
                DbDebugHelper.OnUpdate("Finished saving tables.");
            }
        }
Esempio n. 3
0
        public static void Loader(AbstractDb <int> db, string file)
        {
            if (file == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnUpdate(db.DbSource, null, "achievement_list table will not be loaded."));
                return;
            }

            LuaList list;

            var table   = db.Table;
            var metaGrf = db.ProjectDatabase.MetaGrf;

            string outputPath = GrfPath.Combine(SdeAppConfiguration.TempPath, Path.GetFileName(file));

            byte[] itemData = metaGrf.GetData(file);

            if (itemData == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnUpdate(db.DbSource, file, "File not found."));
                return;
            }

            File.WriteAllBytes(outputPath, itemData);

            if (!File.Exists(outputPath))
            {
                return;
            }

            if (Methods.ByteArrayCompare(itemData, 0, 4, new byte[] { 0x1b, 0x4c, 0x75, 0x61 }, 0))
            {
                // Decompile lub file
                Lub lub  = new Lub(itemData);
                var text = lub.Decompile();
                itemData = EncodingService.DisplayEncoding.GetBytes(text);
                File.WriteAllBytes(outputPath, itemData);
            }

            DbIOMethods.DetectAndSetEncoding(itemData);

            using (LuaReader reader = new LuaReader(outputPath, DbIOMethods.DetectedEncoding)) {
                list = reader.ReadAll();
            }

            LuaKeyValue itemVariable = list.Variables[0] as LuaKeyValue;

            if (itemVariable != null && itemVariable.Key == "achievement_tbl")
            {
                LuaList items = itemVariable.Value as LuaList;

                if (items != null)
                {
                    foreach (LuaKeyValue item in items.Variables)
                    {
                        _loadEntry(table, item);
                    }
                }
            }
            else
            {
                // Possible copy-paste data
                foreach (LuaKeyValue item in list.Variables)
                {
                    _loadEntry(table, item);
                }
            }

            Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, metaGrf.FindTkPath(file), db));
        }