示例#1
0
        private static string _getInCurrentPath(string fileInput)
        {
            string path = 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));
        }
        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));
            }
        }
示例#3
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;
        }
示例#4
0
        public bool Write(string dbPath, string subPath, ServerType serverType, FileType fileType = FileType.Detect, bool isModifiedCheck = false)
        {
            SubPath = subPath;
            string filename    = DbSource.Filename;
            string logicalPath = DbPathLocator.DetectPath(DbSource);

            DestinationServer = serverType;

            FileType = fileType;

            if ((fileType & FileType.Detect) == FileType.Detect)
            {
                if ((DbSource.SupportedFileType & FileType.Txt) == FileType.Txt)
                {
                    FileType = FileType.Txt;
                }

                if ((DbSource.SupportedFileType & FileType.Conf) == FileType.Conf)
                {
                    if (serverType == ServerType.Hercules)
                    {
                        FileType = FileType.Conf;

                        // Alternative name is rAthena specific
                        if (DbSource.AlternativeName != null && !DbSource.AlternativeName.StartsWith("import\\"))
                        {
                            filename = DbSource.AlternativeName ?? filename;
                        }
                    }
                    else if (FileType == FileType.Detect && serverType == ServerType.RAthena)
                    {
                        FileType = FileType.Conf;
                    }
                }

                if (FileType == FileType.Detect)
                {
                    FileType = FileType.Error;
                }
            }

            if (FileType == FileType.Error)
            {
                DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "FileType couldn't be detected.");
                return(false);
            }

            if (DbSource == ServerDbs.Mobs || DbSource == ServerDbs.Mobs2)
            {
                // It's resave
                if (DbPathLocator.GetServerType() == ServerType.Hercules && serverType == ServerType.Hercules)
                {
                    FileType = logicalPath.IsExtension(".conf") ? FileType.Conf : logicalPath.IsExtension(".txt") ? FileType.Txt : FileType;
                }
            }

            if ((DbSource.SupportedFileType & FileType) != FileType)
            {
                DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "FileType not supported.");
                return(false);
            }

            string ext = "." + FileType.ToString().ToLower();

            IsRenewal = false;

            if ((FileType & FileType.Sql) == FileType.Sql)
            {
                if (subPath == "re")
                {
                    FilePath = GrfPath.CombineUrl(dbPath, filename + "_re" + ext);
                }
                else
                {
                    FilePath = GrfPath.CombineUrl(dbPath, filename + ext);
                }
            }
            else
            {
                if (DbSource.UseSubPath)
                {
                    if (subPath == "re")
                    {
                        IsRenewal = true;
                    }

                    if (DbPathLocator.UseAlternative(DbSource))
                    {
                        if ((DbSource.AlternativeName + ext).Contains("import\\"))
                        {
                            FilePath = GrfPath.CombineUrl(dbPath, DbSource.AlternativeName + ext);
                        }
                        else
                        {
                            FilePath = GrfPath.CombineUrl(dbPath, subPath, DbSource.AlternativeName + ext);
                        }
                    }
                    else
                    {
                        FilePath = GrfPath.CombineUrl(dbPath, subPath, filename + ext);
                    }
                }
                else
                {
                    if (DbPathLocator.UseAlternative(DbSource))
                    {
                        FilePath = GrfPath.CombineUrl(dbPath, DbSource.AlternativeName + ext);
                    }
                    else
                    {
                        FilePath = GrfPath.CombineUrl(dbPath, filename + ext);
                    }
                }
            }

            TextFileHelper.LatestFile = FilePath;
            OldPath = DbPathLocator.GetStoredFile(logicalPath);

            if (OldPath == null || !File.Exists(OldPath))
            {
                DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "Source path not found: '" + OldPath + "', cannot save this table.");
                return(false);
            }

            if (!_db.IsEnabled)
            {
                DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "Table not enabled.");
                return(false);
            }

            if (FtpHelper.IsSystemFile(FilePath))
            {
                GrfPath.CreateDirectoryFromFile(FilePath);
            }

            BackupEngine.Instance.Backup(logicalPath);

            if (ForceWrite)
            {
                DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "The table is saving...");
                return(true);
            }

            if (_db.Table.Commands.CommandIndex == -1 && logicalPath.IsExtension(FilePath.GetExtension()))
            {
                if (isModifiedCheck && _db.Table.Tuples.Values.Any(p => !p.Normal))
                {
                    return(true);
                }

                //// If we use the previous output, we should never overwrite the file
                //// because it will eat the previous modifications.
                //if (_db.UsePreviousOutput) {
                //	DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "Output from master DB is more recent (will not be saved).");
                //	return false;
                //}

                if (SdeAppConfiguration.AlwaysOverwriteFiles)
                {
                    _db.DbDirectCopy(this, _db);
                }

                DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "Table not modified (will not be saved).");
                return(false);
            }

            DbDebugHelper.OnWriteStatusUpdate(DbSource, FilePath, _db, "The table is saving...");
            return(true);
        }
示例#5
0
 /// <summary>
 /// Determines if the current server is NovaRO or not.
 /// </summary>
 /// <returns></returns>
 public static bool GetIsNova()
 {
     return(File.Exists(GrfPath.CombineUrl(Path.GetDirectoryName(ProjectConfiguration.DatabasePath), "lapine_db.conf")));
 }