Esempio n. 1
0
        private string _convertPath(string path)
        {
            //return GrfPath.Combine(DestPath, path.Replace(ProjectConfiguration.DatabasePath, "").TrimStart('/', '\\').Replace("/", "\\"));
            FtpUrlInfo url = new FtpUrlInfo(GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath));

            return(path.Replace(GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath), "").TrimStart('/', '\\').Replace(url.Path.TrimStart('/', '\\'), "").TrimStart('/', '\\'));
        }
Esempio n. 2
0
        public void Backup(string file)
        {
            if (!SdeAppConfiguration.BackupsManagerState || !IsStarted || _backupThread.IsCrashed)
            {
                return;
            }
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            try {
                string relativePath = file.ReplaceFirst(GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath) + IOHelper.Slash, "");

                if (String.IsNullOrEmpty(relativePath))
                {
                    return;
                }

                _validateOpened();

                string fullPath = GrfPath.Combine(_paths[_currentId], relativePath);
                string tempFile = TemporaryFilesManager.GetTemporaryFilePath("backup_local_copy_{0:0000}");
                IOHelper.Copy(file, tempFile);

                _localToGrfPath[_currentId][tempFile] = fullPath;
            }
            catch {
            }
        }
Esempio n. 3
0
        private static string _getInParentPath(string fileInput)
        {
            string path = GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath);

            string[] files = fileInput.GetExtension() == null ? new string[] { fileInput + ".txt", fileInput + ".conf" } : new string[] { fileInput };
            return(files.Select(file => GrfPath.CombineUrl(path, file)).FirstOrDefault(FtpHelper.Exists));
        }
Esempio n. 4
0
        public void Backup(string file)
        {
            if (!SdeAppConfiguration.BackupsManagerState || !_isStarted || _isCrashed)
            {
                return;
            }
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            try {
                string relativePath = file.ReplaceFirst(GrfPath.GetDirectoryName(SdeFiles.ServerDbPath) + "\\", "");

                if (String.IsNullOrEmpty(relativePath))
                {
                    return;
                }

                _validateOpened();

                if (!_paths.ContainsKey(_currentId))
                {
                    _paths[_currentId] = _getGrfPath();
                }

                string fullPath = GrfPath.Combine(_paths[_currentId], relativePath);
                string tempFile = TemporaryFilesManager.GetTemporaryFilePath("backup_local_copy_{0:0000}");
                File.Copy(file, tempFile);

                _grf.Commands.AddFileAbsolute(fullPath, tempFile);
            }
            catch { }
        }
        private Dictionary <int, int> _getWeaponClasses()
        {
            Dictionary <int, int> table = new Dictionary <int, int>();
            var accIdPath = ProjectConfiguration.SyncAccId;

            for (int i = 0; i <= 30; i++)
            {
                table[i] = i;
            }

            if (_database.MetaGrf.GetData(ProjectConfiguration.SyncAccId) == null || _database.MetaGrf.GetData(ProjectConfiguration.SyncAccName) == null)
            {
                return(table);
            }

            var weaponPath = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "weapontable" + Path.GetExtension(accIdPath));
            var weaponData = _database.MetaGrf.GetData(weaponPath);

            if (weaponData == null)
            {
                return(table);
            }

            var weaponTable = new LuaParser(weaponData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(weaponData), EncodingService.DisplayEncoding);
            var weaponIds   = LuaHelper.GetLuaTable(weaponTable, "Weapon_IDs");
            var weaponExpansionNameTable = LuaHelper.GetLuaTable(weaponTable, "Expansion_Weapon_IDs");

            var ids = LuaHelper.SetIds(weaponIds, "Weapon_IDs");

            foreach (var id in ids)
            {
                if (id.Value == 24)
                {
                    continue;
                }

                if (id.Value <= 30)
                {
                    table[id.Value] = id.Value;
                }
                else
                {
                    string sval;
                    if (weaponExpansionNameTable.TryGetValue("[" + id.Key + "]", out sval))
                    {
                        int ival;
                        if (ids.TryGetValue(sval, out ival))
                        {
                            table[id.Value] = ival;
                        }
                    }
                }
            }

            return(table);
        }
Esempio n. 6
0
        private void _listViewResults_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = _listViewResults.SelectedItem as FtpEntry;

            if (item != null)
            {
                if (item.Name == "..")
                {
                    _setListing(GrfPath.GetDirectoryName(_currentPath));
                    return;
                }

                _setListing(GrfPath.CombineUrl(_currentPath, item.Name));
            }
        }
Esempio n. 7
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. 8
0
 private void _listViewResults_KeyDown(object sender, KeyEventArgs e)
 {
     try {
         if (e.Key == Key.Enter)
         {
             e.Handled = true;
             _listViewResults_MouseDoubleClick(null, null);
         }
         else if (e.Key == Key.Back)
         {
             e.Handled = true;
             _setListing(GrfPath.GetDirectoryName(_currentPath));
         }
     }
     catch (Exception err) {
         ErrorHandler.HandleException(err);
     }
 }
Esempio n. 9
0
        private void _map()
        {
            if (_hasBeenMapped)
            {
                return;
            }

            // List all files
            var basePath = GrfPath.GetDirectoryName(_info.Path).TrimEnd('/');

            DbDebugHelper.OnSftpUpdate("listing files...");
            List <ChannelSftp.LsEntry> files = _sftp.GetFileListAdv(basePath);

            DbDebugHelper.OnSftpUpdate("listing " + basePath);

            foreach (var file in files)
            {
                var cur = file.getFilename();

                if (file.getAttrs().isDir() && cur != "." && cur != ".." &&
                    (cur == "re" || cur == "pre-re" || cur == "import"))
                {
                    var subPath = basePath + "/" + cur;
                    DbDebugHelper.OnSftpUpdate("listing " + subPath);

                    List <ChannelSftp.LsEntry> filesSub = _sftp.GetFileListAdv(subPath);

                    foreach (var subfile in filesSub)
                    {
                        if (!subfile.getAttrs().isDir())
                        {
                            _entries[subPath + "/" + subfile.getFilename()] = subfile;
                        }
                    }
                }
                else
                {
                    _entries[basePath + "/" + cur] = file;
                }
            }

            DbDebugHelper.OnSftpUpdate("" + _entries.Count + " files found.");
            _hasBeenMapped = true;
        }
Esempio n. 10
0
        /// <summary>
        /// Goes up in the parent folder until the path is found.
        /// </summary>
        /// <param name="db">The sub path to find.</param>
        /// <returns>The path found.</returns>
        public static string DetectPathAll(string db)
        {
            try {
                string path = ProjectConfiguration.DatabasePath;

                while (path != null)
                {
                    if (FtpHelper.Exists(GrfPath.Combine(path, db)))
                    {
                        return(GrfPath.Combine(path, db));
                    }

                    path = GrfPath.GetDirectoryName(path);
                }

                return(null);
            }
            catch {
                return(null);
            }
        }
Esempio n. 11
0
        public void Start(string dbPath)
        {
            if (!SdeAppConfiguration.BackupsManagerState || _backupThread.IsCrashed)
            {
                return;
            }
            if (dbPath == null)
            {
                throw new ArgumentNullException("dbPath");
            }

            _currentId++;

            _validateOpened();

            BackupInfo info = new BackupInfo(new TextConfigAsker(new byte[] { }));

            info.DestinationPath = GrfPath.GetDirectoryName(dbPath);

            if (!_paths.ContainsKey(_currentId))
            {
                _paths[_currentId] = _getGrfPath();
            }

            if (!_localToGrfPath.ContainsKey(_currentId))
            {
                _localToGrfPath[_currentId] = new Dictionary <string, string>();
            }

            string fullPath = GrfPath.CombineUrl(_paths[_currentId], InfoName);
            string tempFile = TemporaryFilesManager.GetTemporaryFilePath("backup_local_copy_{0:0000}");

            File.WriteAllBytes(tempFile, info.GetData());
            _localToGrfPath[_currentId][tempFile] = fullPath;

            IsStarted = true;
        }
Esempio n. 12
0
        public static bool GetIdToSpriteTable(AbstractDb <int> db, ViewIdTypes type, out Dictionary <int, string> outputIdsToSprites, out string error)
        {
            outputIdsToSprites = new Dictionary <int, string>();
            error = null;

            if (db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId) == null || db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName) == null)
            {
                error = "The accessory ID table or accessory name table has not been set, the paths are based on those.";
                return(false);
            }

            int    temp_i;
            string temp_s;
            var    accIdPath = ProjectConfiguration.SyncAccId;
            Dictionary <string, int> ids;

            switch (type)
            {
            case ViewIdTypes.Weapon:
                if (_weaponBuffer.IsBuffered())
                {
                    outputIdsToSprites = _weaponBuffer.Ids;
                    error = _weaponBuffer.Error;
                    return(_weaponBuffer.Result);
                }

                var weaponPath = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "weapontable" + Path.GetExtension(accIdPath));
                var weaponData = db.ProjectDatabase.MetaGrf.GetData(weaponPath);

                if (weaponData == null)
                {
                    error = "Couldn't find " + weaponPath;
                    _weaponBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                var weaponTable     = new LuaParser(weaponData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(weaponData), EncodingService.DisplayEncoding);
                var weaponIds       = GetLuaTable(weaponTable, "Weapon_IDs");
                var weaponNameTable = GetLuaTable(weaponTable, "WeaponNameTable");

                ids = SetIds(weaponIds, "Weapon_IDs");

                foreach (var pair in weaponNameTable)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _weaponBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Npc:
                if (_npcBuffer.IsBuffered())
                {
                    outputIdsToSprites = _npcBuffer.Ids;
                    error = _npcBuffer.Error;
                    return(_npcBuffer.Result);
                }

                var npcPathSprites = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "jobname" + Path.GetExtension(accIdPath));
                var npcPathIds     = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "npcIdentity" + Path.GetExtension(accIdPath));
                var npcDataSprites = db.ProjectDatabase.MetaGrf.GetData(npcPathSprites);
                var npcDataIds     = db.ProjectDatabase.MetaGrf.GetData(npcPathIds);

                if (npcDataSprites == null)
                {
                    error = "Couldn't find " + npcPathSprites;
                    _npcBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                if (npcDataIds == null)
                {
                    error = "Couldn't find " + npcPathIds;
                    _npcBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                //var itemDb = db.GetMeta<int>(ServerDbs.Items);
                var jobname = new LuaParser(npcDataSprites, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(npcDataSprites), EncodingService.DisplayEncoding);
                var jobtbl  = new LuaParser(npcDataIds, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(npcDataIds), EncodingService.DisplayEncoding);

                var jobtblT  = GetLuaTable(jobtbl, "jobtbl");
                var jobnameT = GetLuaTable(jobname, "JobNameTable");

                ids = SetIds(jobtblT, "jobtbl");

                foreach (var pair in jobnameT)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _npcBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Headgear:
                if (_headgearBuffer.IsBuffered())
                {
                    outputIdsToSprites = _headgearBuffer.Ids;
                    error = _headgearBuffer.Error;
                    return(_headgearBuffer.Result);
                }

                var redirectionTable = GetRedirectionTable();
                var dataAccId        = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId);
                var dataAccName      = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName);
                var itemDb           = db.GetMeta <int>(ServerDbs.Items);
                var accId            = new LuaParser(dataAccId, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccId), EncodingService.DisplayEncoding);
                var accName          = new LuaParser(dataAccName, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccName), EncodingService.DisplayEncoding);
                var accIdT           = GetLuaTable(accId, "ACCESSORY_IDs");
                var accNameT         = GetLuaTable(accName, "AccNameTable");
                outputIdsToSprites = _getViewIdTable(accIdT, accNameT);

                accIdT.Clear();
                accNameT.Clear();

                var resourceToIds = new Dictionary <string, int>();

                if (ProjectConfiguration.HandleViewIds)
                {
                    try {
                        List <ReadableTuple <int> > headgears = itemDb.FastItems.Where(p => ItemParser.IsArmorType(p) && (p.GetIntNoThrow(ServerItemAttributes.Location) & 7937) != 0).OrderBy(p => p.GetIntNoThrow(ServerItemAttributes.ClassNumber)).ToList();
                        _loadFallbackValues(outputIdsToSprites, headgears, accIdT, accNameT, resourceToIds, redirectionTable);
                    }
                    catch (Exception err) {
                        error = err.ToString();
                        _headgearBuffer.Buffer(outputIdsToSprites, false, error);
                        return(false);
                    }
                }

                _headgearBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Shield:
                if (_shieldBuffer.IsBuffered())
                {
                    outputIdsToSprites = _shieldBuffer.Ids;
                    error = _shieldBuffer.Error;
                    return(_shieldBuffer.Result);
                }

                var shieldPath = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "ShieldTable" + Path.GetExtension(accIdPath));
                var shieldData = db.ProjectDatabase.MetaGrf.GetData(shieldPath);

                if (shieldData == null)
                {
                    outputIdsToSprites[1] = "_°¡µå";
                    outputIdsToSprites[2] = "_¹öŬ·¯";
                    outputIdsToSprites[3] = "_½¯µå";
                    outputIdsToSprites[4] = "_¹Ì·¯½¯µå";
                    outputIdsToSprites[5] = "";
                    outputIdsToSprites[6] = "";
                }
                else
                {
                    _debugStatus = "OK";

                    var shieldTable = new LuaParser(shieldData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(shieldData), EncodingService.DisplayEncoding);

                    _debugStatus = "LoadTables";

                    var shieldIds       = GetLuaTable(shieldTable, "Shield_IDs");
                    var shieldNameTable = GetLuaTable(shieldTable, "ShieldNameTable");
                    var shieldMapTable  = GetLuaTable(shieldTable, "ShieldMapTable");

                    ids = SetIds(shieldIds, "Shield_IDs");
                    Dictionary <int, string> idsToSprite = new Dictionary <int, string>();

                    foreach (var pair in shieldNameTable)
                    {
                        temp_s = pair.Key.Trim('[', ']');

                        if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                        {
                            temp_s = pair.Value.Trim('\"');
                            idsToSprite[temp_i]        = temp_s;
                            outputIdsToSprites[temp_i] = temp_s;
                        }
                    }

                    foreach (var pair in shieldMapTable)
                    {
                        var key = pair.Key.Trim('[', ']', '\t');
                        int id1;

                        if (ids.TryGetValue(key, out id1))
                        {
                            int id2;
                            temp_s = pair.Value.Trim('\"', '\t');

                            if (ids.TryGetValue(temp_s, out id2) || Int32.TryParse(temp_s, out id2))
                            {
                                if (idsToSprite.TryGetValue(id2, out temp_s))
                                {
                                    outputIdsToSprites[id1] = temp_s;
                                }
                            }
                        }
                    }

                    error = PreviewHelper.ViewIdIncrease;
                }

                _shieldBuffer.Buffer(outputIdsToSprites, true, error);
                return(true);

            case ViewIdTypes.Garment:
                if (_garmentBuffer.IsBuffered())
                {
                    outputIdsToSprites = _garmentBuffer.Ids;
                    error = _garmentBuffer.Error;
                    return(_garmentBuffer.Result);
                }

                var robeSpriteName = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "spriterobename" + Path.GetExtension(accIdPath));
                var robeSpriteId   = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "spriterobeid" + Path.GetExtension(accIdPath));
                var robeNameData   = db.ProjectDatabase.MetaGrf.GetData(robeSpriteName);
                var robeIdData     = db.ProjectDatabase.MetaGrf.GetData(robeSpriteId);

                if (robeNameData == null)
                {
                    error = "Couldn't find " + robeSpriteName;
                    _garmentBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                if (robeIdData == null)
                {
                    error = "Couldn't find " + robeSpriteId;
                    _garmentBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                var robeNameTable = new LuaParser(robeNameData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(robeNameData), EncodingService.DisplayEncoding);
                var robeIdTable   = new LuaParser(robeIdData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(robeIdData), EncodingService.DisplayEncoding);
                var robeNames     = GetLuaTable(robeNameTable, "RobeNameTable");
                var robeIds       = GetLuaTable(robeIdTable, "SPRITE_ROBE_IDs");

                ids = SetIds(robeIds, "SPRITE_ROBE_IDs");

                foreach (var pair in robeNames)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _garmentBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);
            }

            return(false);
        }