protected string ProcessTextCommand_ExportAll(string args) { try { string str = ""; if (args.ToLower().Trim() == "-t") { foreach (var preset in mConfiguration.PresetLibrary.Presets) { str += JsonConvert.SerializeObject(preset) + "\r\n"; } } else { foreach (var preset in mConfiguration.PresetLibrary.Presets) { str += WaymarkPresetExport.GetExportString(preset) + "\r\n"; } } Win32Clipboard.CopyTextToClipboard(str); return(""); } catch (Exception e) { PluginLog.Log($"Unknown error occured while trying to copy presets to clipboard: {e}"); return("Unknown error occured while trying to copy presets to clipboard."); } }
protected string ProcessTextCommand_Export(string args) { var parameters = args.Split(); bool includeTimestamp = parameters.Contains("-t"); bool useGameSlot = parameters.Contains("-g"); int scratchVal; var slotIndexNumbers = parameters.Where(x => int.TryParse(x, out scratchVal)).ToList(); WaymarkPreset presetToExport = null; try { if (slotIndexNumbers.Count < 1) { return("No slot or index numbers were provided."); } else if (slotIndexNumbers.Count == 1) { int indexToExport = int.Parse(slotIndexNumbers[0]); if (useGameSlot) { if (indexToExport >= 1 && indexToExport <= MemoryHandler.MaxPresetSlotNum) { presetToExport = WaymarkPreset.Parse(MemoryHandler.ReadSlot((uint)indexToExport)); } else { return($"An invalid game slot number ({indexToExport}) was provided."); } } else { if (indexToExport >= 0 && indexToExport < mConfiguration.PresetLibrary.Presets.Count) { presetToExport = mConfiguration.PresetLibrary.Presets[indexToExport]; } else { return($"An invalid library index ({indexToExport}) was provided."); } } string exportStr = ""; if (includeTimestamp) { exportStr = JsonConvert.SerializeObject(presetToExport); } else { exportStr = WaymarkPresetExport.GetExportString(presetToExport); } Win32Clipboard.CopyTextToClipboard(exportStr); return("Copied to clipboard."); } else { int indexToExport = int.Parse(slotIndexNumbers[0]); int exportTargetIndex = int.Parse(slotIndexNumbers[1]); if (useGameSlot) { if (indexToExport >= 1 && indexToExport <= MemoryHandler.MaxPresetSlotNum) { presetToExport = WaymarkPreset.Parse(MemoryHandler.ReadSlot((uint)indexToExport)); } else { return($"An invalid game slot number to export ({indexToExport}) was provided."); } } else { if (indexToExport >= 0 && indexToExport < mConfiguration.PresetLibrary.Presets.Count) { presetToExport = mConfiguration.PresetLibrary.Presets[indexToExport]; } else { return($"An invalid library index ({indexToExport}) was provided."); } } if (exportTargetIndex >= 1 && exportTargetIndex <= MemoryHandler.MaxPresetSlotNum) { MemoryHandler.WriteSlot((uint)exportTargetIndex, presetToExport.GetAsGamePreset()); return($"Preset exported to game slot."); } else { return($"An invalid game slot number({exportTargetIndex}) was provided as the target."); } } } catch (Exception e) { PluginLog.Log($"Unknown error occured while export the preset: {e}"); return("Unknown error occured while trying to export the preset."); } }