/// <summary> /// Save data file as a CSV /// </summary> /// <param name="sheet"></param> /// <param name="language"></param> /// <param name="path"></param> public static void SaveAsCsv(Ex.Relational.IRelationalSheet sheet, Language language, string path) { using (var s = new StreamWriter(path, false, Encoding.UTF8)) { var indexLine = new StringBuilder("key"); var nameLine = new StringBuilder("#"); var typeLine = new StringBuilder("int32"); var colIndices = new List <int>(); foreach (var col in sheet.Header.Columns) { indexLine.AppendFormat(",{0}", col.Index); nameLine.AppendFormat(",{0}", col.Name); typeLine.AppendFormat(",{0}", col.ValueType); colIndices.Add(col.Index); } s.WriteLine(indexLine); s.WriteLine(nameLine); s.WriteLine(typeLine); ExdHelper.WriteRows(s, sheet, language, colIndices, true); } }
public override async Task <bool> InvokeAsync(string paramList) { const string CsvFileFormat = "exd-all/{0}{1}.csv"; IEnumerable <string> filesToExport; if (string.IsNullOrWhiteSpace(paramList)) { filesToExport = _Realm.GameData.AvailableSheets; } else { filesToExport = paramList.Split(' ').Select(_ => _Realm.GameData.FixName(_)); } var successCount = 0; var failCount = 0; foreach (var name in filesToExport) { var sheet = _Realm.GameData.GetSheet(name); foreach (var lang in sheet.Header.AvailableLanguages) { var code = lang.GetCode(); if (code.Length > 0) { code = "." + code; } var target = new FileInfo(Path.Combine(_Realm.GameVersion, string.Format(CsvFileFormat, name, code))); try { if (!target.Directory.Exists) { target.Directory.Create(); } ExdHelper.SaveAsCsv(sheet, lang, target.FullName, false); ++successCount; } catch (Exception e) { OutputError("Export of {0} failed: {1}", name, e.Message); try { if (target.Exists) { target.Delete(); } } catch { } ++failCount; } } } OutputInformation("{0} files exported, {1} failed", successCount, failCount); return(true); }
public override void Invoke(string[] param) { const string CsvFileFormat = "rawexd/{0}.csv"; IEnumerable <string> filesToExport; if (param == null || param.Length == 0) { filesToExport = _Realm.GameData.AvailableSheets; } else { filesToExport = param.Select(_ => _Realm.GameData.FixName(_)); } var successCount = 0; var failCount = 0; foreach (var name in filesToExport) { var target = new FileInfo(Path.Combine(_Realm.GameVersion, string.Format(CsvFileFormat, name))); try { var sheet = _Realm.GameData.GetSheet(name); if (!target.Directory.Exists) { target.Directory.Create(); } ExdHelper.SaveAsCsv(sheet, Ex.Language.None, target.FullName, true); ++successCount; } catch (Exception e) { OutputError(string.Format("Export of {0} failed: {1}", name, e.Message)); try { if (target.Exists) { target.Delete(); } } catch { } ++failCount; } } OutputInformation(string.Format("{0} files exported, {1} failed", successCount, failCount)); }
/// <summary> /// Obtain game sheets from the game data /// </summary> /// <param name="paramList"></param> /// <returns></returns> public override void Invoke(string[] param) { var versionPath = _Realm.GameVersion; if (param?.Any(_ => _ == "/UseDefinitionVersion") ?? false) { versionPath = _Realm.DefinitionVersion; } // TODO correct way to do this now? param?.ToList().ForEach(_ => AssignVariables(this, _)); //old: AssignVariables(this, paramList); const string CsvFileFormat = "raw-exd-all/{0}{1}.csv"; IEnumerable <string> filesToExport; // Gather files to export, may be split by params. if (param == null || param.Length == 0) { filesToExport = _Realm.GameData.AvailableSheets; } else { filesToExport = param.Select(_ => _Realm.GameData.FixName(_)); } // Action counts var successCount = 0; var failCount = 0; var currentCount = 0; var total = filesToExport.Count(); // Process game files. foreach (var name in filesToExport) { currentCount++; var sheet = _Realm.GameData.GetSheet(name); // Loop through all available languages foreach (var lang in sheet.Header.AvailableLanguages) { var code = lang.GetCode(); if (code.Length > 0) { code = "." + code; } var target = new FileInfo(Path.Combine(versionPath, string.Format(CsvFileFormat, name, code))); try { if (!target.Directory.Exists) { target.Directory.Create(); } // Save OutputInformation(string.Format("[{0}/{1}] Processing: {2} - Language: {3}", currentCount, total, name, lang.GetSuffix())); ExdHelper.SaveAsCsv(sheet, lang, target.FullName, true); ++successCount; } catch (Exception e) { OutputError(string.Format("Export of {0} failed: {1}", name, e.Message)); try { if (target.Exists) { target.Delete(); } } catch { } ++failCount; } } } OutputInformation(string.Format("{0} files exported, {1} failed", successCount, failCount)); }
public async Task RipAsync(string paramList, CancellationToken cancellationToken) { const string csvFileFormat = "exd-all/{0}{1}.csv"; var arr = _realm.RealmReversed; IEnumerable <string> filesToExport; _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"Getting sheet list...")); _logger.LogInformation("Getting sheet list..."); if (string.IsNullOrWhiteSpace(paramList)) { filesToExport = arr.GameData.AvailableSheets; } else { filesToExport = paramList.Split(' ').Select(_ => arr.GameData.FixName(_)); } var successCount = 0; var failCount = 0; foreach (var name in filesToExport) { var sheet = arr.GameData.GetSheet(name); var language = _realm.RealmReversed.GameData.ActiveLanguage == Language.None ? sheet.Header.AvailableLanguages : new List <Language> { _realm.RealmReversed.GameData.ActiveLanguage }; foreach (var lang in language /*sheet.Header.AvailableLanguages*/) { var code = lang.GetCode(); if (code.Length > 0) { code = "." + code; } var target = new FileInfo(Path.Combine(arr.GameVersion, string.Format(csvFileFormat, name, code))); try { if (!target.Directory.Exists) { target.Directory.Create(); } await Task.Run(() => ExdHelper.SaveAsCsv(sheet, lang, target.FullName, false)); _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"{target.Name}")); _logger.LogInformation($"Exported {target.Name}."); ++successCount; } catch (Exception ex) { _logger.LogError(ex, $"Export of {target.Name} failed."); try { if (target.Exists) { target.Delete(); } } catch { } ++failCount; } } } var returnValue = $"{successCount} files exported, {failCount} failed"; _logger.LogInformation(returnValue); _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(returnValue)); }