generated from goatcorp/SamplePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from perappu/feature/exportlogs
Feature/exportlogs
- Loading branch information
Showing
7 changed files
with
191 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Dalamud.DrunkenToad; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using WhoSaidWhatNow.Objects; | ||
|
||
namespace WhoSaidWhatNow.Services | ||
{ | ||
public class FileService | ||
{ | ||
/// <summary> | ||
/// OpenFileDialog for individual | ||
/// </summary> | ||
/// <param name="plugin">the plugin</param> | ||
/// <param name="playerName">player name</param> | ||
public static void OpenFileDialog(Plugin plugin, string playerName) | ||
{ | ||
plugin.FileDialogManager.SaveFileDialog("Save log...", "Text File{.txt}", | ||
Regex.Replace(playerName, "[^a-zA-Z0-9]", String.Empty) + "-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", | ||
".txt", (isOk, selectedFile) => | ||
{ | ||
if (isOk) | ||
{ | ||
FileService.SaveIndividualLog(selectedFile); | ||
} | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// OpenFileDialog for groups | ||
/// </summary> | ||
/// <param name="plugin">the plugin</param> | ||
/// <param name="group">KeyValuePair string for group name, Dictionary<Player, Boolean> for contents of group</param> | ||
public static void OpenFileDialog(Plugin plugin, KeyValuePair<string, (string NAME, Dictionary<Player, bool> PLAYERS)> group) | ||
{ | ||
plugin.FileDialogManager.SaveFileDialog("Save log...", "Text File{.txt}", | ||
Regex.Replace(group.Key, "[^a-zA-Z0-9]", String.Empty) + "-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", | ||
".txt", (isOk, selectedFile) => | ||
{ | ||
if (isOk) | ||
{ | ||
FileService.SaveGroupLog(selectedFile, group.Value.PLAYERS); | ||
} | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Save individual character log to file | ||
/// </summary> | ||
/// <param name="path">file path passed from save file dialog</param> | ||
public static void SaveIndividualLog(string path) | ||
{ | ||
try | ||
{ | ||
using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false)) | ||
{ | ||
foreach (var c in from KeyValuePair<DateTime, ChatEntry> c in Plugin.ChatEntries | ||
where Plugin.Config.ChannelToggles[c.Value.Type] == true && c.Value.Sender.Name.Contains(Plugin.SelectedPlayer.Name) | ||
select c) | ||
{ | ||
string tag = Plugin.Config.Formats[c.Value.Type]; | ||
file.WriteLine(c.Value.CreateMessage(tag)); | ||
} | ||
ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Successfully saved log: " + path); | ||
} | ||
} | ||
catch | ||
{ | ||
ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Failed to save log."); | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Save group log to file | ||
/// </summary> | ||
/// <param name="path">file path passed from save file dialog</param> | ||
/// <param name="players">passed dictionary of players</param> | ||
public static void SaveGroupLog(string path, Dictionary<Player, Boolean> players) | ||
{ | ||
try | ||
{ | ||
using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false)) | ||
{ | ||
foreach (var c in Plugin.ChatEntries) | ||
{ | ||
// if we are displaying this type of message; | ||
if (Plugin.Config.ChannelToggles[c.Value.Type] == true) | ||
{ | ||
// and if the player is among the tracked; | ||
var p = Plugin.Players.Find(p => c.Value.Sender.Name.Contains(p.Name)); | ||
if (players[p!]) | ||
{ | ||
string tag = Plugin.Config.Formats[c.Value.Type]; | ||
file.WriteLine(c.Value.CreateMessage(tag)); | ||
} | ||
} | ||
} | ||
|
||
ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Successfully saved log: " + path); | ||
} | ||
} | ||
catch | ||
{ | ||
ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Failed to save log."); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters