Example #1
0
        public bool Load(ServerDbs dbSource)
        {
            DbSource = dbSource;
            string path = DbPathLocator.DetectPath(DbSource);

            TextFileHelper.LatestFile = path;

            if (String.IsNullOrEmpty(path))
            {
                if (_db.ThrowFileNotFoundException)
                {
                    DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), "File not found '" + DbSource + "'.", ErrorLevel.NotSpecified);
                }

                return(false);
            }

            FileType = DbPathLocator.GetFileType(path);
            FilePath = path;
            DbPathLocator.StoreFile(FilePath);
            DbDebugHelper.OnLoaded(DbSource, FilePath, _db);
            return(true);
        }
Example #2
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);
        }