public SftpDb(string path) { DestPath = GrfPath.Combine(SdeAppConfiguration.ProgramDataPath, path.GetHashCode().ToString(CultureInfo.InvariantCulture)); var file = GrfPath.Combine(DestPath, "files.dat"); GrfPath.CreateDirectoryFromFile(file); _config = new ConfigAsker(file); }
public void Set(string dataPath, string urlPath, ChannelSftp.LsEntry entry) { urlPath = _convertPath(urlPath); _config[urlPath] = entry.getAttrs().getMTime().ToString(CultureInfo.InvariantCulture); var dest = _convertLocalPath(urlPath); GrfPath.CreateDirectoryFromFile(dest); GrfPath.Delete(dest); File.Copy(dataPath, dest); }
private void _buttonExport_Click(object sender, RoutedEventArgs e) { try { var tuple = ViewIdPreviewDialog.LatestTupe; if (tuple == null) { return; } var sprite = LuaHelper.GetSpriteFromViewId(tuple.GetIntNoThrow(ServerItemAttributes.ClassNumber), LuaHelper.ViewIdTypes.Headgear, SdeEditor.Instance.ProjectDatabase.GetDb <int>(ServerDbs.Items), tuple); string[] files = new string[] { @"data\sprite\¾ÆÀÌÅÛ\" + sprite + ".spr", @"data\sprite\¾ÆÀÌÅÛ\" + sprite + ".act", @"data\sprite\¾Ç¼¼»ç¸®\³²\³²_" + sprite + ".spr", @"data\sprite\¾Ç¼¼»ç¸®\³²\³²_" + sprite + ".act", @"data\sprite\¾Ç¼¼»ç¸®\¿©\¿©_" + sprite + ".spr", @"data\sprite\¾Ç¼¼»ç¸®\¿©\¿©_" + sprite + ".act", @"data\texture\À¯ÀúÀÎÅÍÆäÀ̽º\collection\" + sprite + ".bmp", @"data\texture\À¯ÀúÀÎÅÍÆäÀ̽º\item\" + sprite + ".bmp" }; string path = PathRequest.FolderEditor(); if (path == null) { return; } var grf = SdeEditor.Instance.ProjectDatabase.MetaGrf; foreach (var file in files) { var data = grf.GetData(file); if (data != null) { string subPath = GrfPath.Combine(path, file); GrfPath.CreateDirectoryFromFile(subPath); File.WriteAllBytes(subPath, data); } } OpeningService.OpenFolder(path); } catch (Exception err) { ErrorHandler.HandleException(err); } }
public App() { Configuration.ConfigAsker = MapcacheConfiguration.ConfigAsker; Settings.TempPath = GrfPath.Combine(MapcacheConfiguration.ProgramDataPath, "~tmp\\" + MapcacheConfiguration.ProcessId); ErrorHandler.SetErrorHandler(new DefaultErrorHandler()); if (!Directory.Exists(Settings.TempPath)) { try { GrfPath.CreateDirectoryFromFile(Settings.TempPath); } catch { } } ClearTemporaryFiles(); }
public void Save(string filename) { if (!File.Exists(filename)) { GrfPath.CreateDirectoryFromFile(filename); using (var writer = File.Create(filename)) { Save(writer); } return; } string tempFile = TemporaryFilesManager.GetTemporaryFilePath(Process.GetCurrentProcess().Id + "_mapcache_{0:0000}.dat"); using (var writer = File.Create(tempFile)) { Save(writer); } GrfPath.CreateDirectoryFromFile(filename); GrfPath.Delete(filename); File.Copy(tempFile, filename); GrfPath.Delete(tempFile); }
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); }
public bool Write(string dbPath, string subPath, ServerType serverType, FileType fileType = FileType.Detect) { SubPath = subPath; string filename = DbSource.Filename; 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; filename = DbSource.AlternativeName ?? filename; } } if (FileType == FileType.Detect) { FileType = FileType.Error; } } if (FileType == FileType.Error) { return(false); } if ((DbSource.SupportedFileType & FileType) != FileType) { return(false); } string ext = "." + FileType.ToString().ToLower(); IsRenewal = false; if ((FileType & FileType.Sql) == FileType.Sql) { if (subPath == "re") { FilePath = GrfPath.Combine(dbPath, filename + "_re" + ext); } else { FilePath = GrfPath.Combine(dbPath, filename + ext); } } else { if (DbSource.UseSubPath) { if (subPath == "re") { IsRenewal = true; } FilePath = GrfPath.Combine(dbPath, subPath, filename + ext); } else { FilePath = GrfPath.Combine(dbPath, filename + ext); } } TextFileHelper.LatestFile = FilePath; string logicalPath = AllLoaders.DetectPath(DbSource); OldPath = AllLoaders.GetStoredFile(logicalPath); if (OldPath == null || !File.Exists(OldPath)) { return(false); } if (_db.Attached["IsEnabled"] != null && !(bool)_db.Attached["IsEnabled"]) { return(false); } GrfPath.CreateDirectoryFromFile(FilePath); if (!_db.Table.Commands.IsModified && logicalPath.IsExtension(FilePath.GetExtension())) { BackupEngine.Instance.Backup(logicalPath); _db.DbDirectCopy(this, _db); return(false); } BackupEngine.Instance.Backup(logicalPath); return(true); }
public static void DbItemGroupWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { try { if (debug.FileType == FileType.Txt) { string currentDirectory = Path.GetDirectoryName(debug.FilePath); string parentDirectory = Path.GetDirectoryName(currentDirectory); var itemDb = db.GetMeta <int>(ServerDbs.Items); ServerType source = AllLoaders.GetServerType(); using (StreamWriter writerPrimary = new StreamWriter(debug.FilePath)) { // currentDirectory = something\db\pre-re // parentDirectory = something\db // outmostDirectory = something if (source == ServerType.Hercules) { // This means we read the file from Hercules db.Attached["0"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_bluebox.txt", new HashSet <int> { 1 }); db.Attached["1"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_violetbox.txt", new HashSet <int> { 2 }); db.Attached["2"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_cardalbum.txt", new HashSet <int> { 3, 44 }); db.Attached["3"] = new Tuple <string, HashSet <int> >("db/item_findingore.txt", new HashSet <int> { 6 }); db.Attached["4"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_giftbox.txt", new HashSet <int> { 4, 28, 29, 30, 31, 34, 43 }); db.Attached["5"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_misc.txt", new HashSet <int> { 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }); } List <Tuple <string, HashSet <int> > > loadedItems = db.Attached.Values.OfType <Tuple <string, HashSet <int> > >().OrderBy(p => p.Item2.Count).ToList(); List <ReadableTuple <TKey> > allTuples; if (source == ServerType.Hercules) { allTuples = db.Table.FastItems.Select(p => db.Table.Copy(p.GetKey <TKey>())).ToList(); List <string> constantsList = Constants.Keys.ToList(); Dictionary <int, int> matches = new Dictionary <int, int>(); Table <int, ReadableTuple <int> > table = db.GetMeta <int>(ServerDbs.Items); for (int i = 0; i < allTuples.Count; i++) { var tuple = allTuples[i]; int key = tuple.GetKey <int>(); if (matches.ContainsKey(key)) { tuple.SetRawValue(0, matches[key]); continue; } var res2 = table.TryGetTuple(key); if (res2 != null) { string name = res2.GetValue(ServerItemAttributes.AegisName).ToString(); string closestString = Methods.ClosestString(name, constantsList); int groupId = Constants[closestString]; matches[key] = groupId; tuple.SetRawValue(0, matches[key]); } else { debug.ReportException("Key not found : " + key); } } } else { allTuples = db.Table.FastItems; } for (int i = 0; i < loadedItems.Count; i++) { var tuple = loadedItems[i]; string importPath = tuple.Item1.Trim(' ', '\t'); string temp = Path.GetDirectoryName(importPath); string outputPath = ""; var set = tuple.Item2; int level = 0; while (!string.IsNullOrEmpty(temp)) { temp = Path.GetDirectoryName(temp); level++; } string internalPath = ""; if (level == 2) { outputPath = "db/" + debug.SubPath + "/" + Path.GetFileName(importPath); internalPath = debug.SubPath + "/" + Path.GetFileName(importPath); } else if (level == 1) { outputPath = "db/" + Path.GetFileName(importPath); internalPath = Path.GetFileName(importPath); } string filePath = GrfPath.Combine(parentDirectory, internalPath); GrfPath.CreateDirectoryFromFile(filePath); List <ReadableTuple <TKey> > tuples; if (i == loadedItems.Count - 1) { //outputeverything tuples = allTuples; } else { tuples = allTuples.Where(p => set.Contains(p.GetKey <int>())).ToList(); for (int j = 0; j < tuples.Count; j++) { allTuples.Remove(tuples[j]); } } using (StreamWriter writer = new StreamWriter(filePath)) { foreach (ReadableTuple <TKey> tup in tuples.OrderBy(p => p.GetKey <TKey>())) { Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)tup.GetRawValue(1); int key = tup.GetKey <int>(); foreach (var pair in dico.OrderBy(p => p.Key)) { var dbTuple = itemDb.TryGetTuple(pair.Key); List <string> items = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList(); RemoveDefaultValues(items); writer.WriteLine(key + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } writer.WriteLine(); } } writerPrimary.WriteLine("import: " + outputPath); } } } else if (debug.FileType == FileType.Conf) { StringBuilder builder = new StringBuilder(); var dbItems = db.GetMeta <int>(ServerDbs.Items); List <string> aegisNames = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.AegisName.Index)).ToList(); List <string> names = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.Name.Index)).ToList(); foreach (int id in db.Table.FastItems.Select(p => p.GetKey <int>()).OrderBy(p => p)) { builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, id, aegisNames, names)); builder.AppendLine(); } File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default); } } catch (Exception err) { debug.ReportException(err); } }