add intro UI for first time registration, add FileCacheManager to scan and rescan for file changes, fix namings, polish UI for normal usage
This commit is contained in:
193
MareSynchronos/UI/IntroUI.cs
Normal file
193
MareSynchronos/UI/IntroUI.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using ImGuiNET;
|
||||
using MareSynchronos.FileCacheDB;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.WebAPI;
|
||||
|
||||
namespace MareSynchronos.UI
|
||||
{
|
||||
internal class IntroUI : Window, IDisposable
|
||||
{
|
||||
private readonly UIShared _uiShared;
|
||||
private readonly Configuration _pluginConfiguration;
|
||||
private readonly FileCacheManager _fileCacheManager;
|
||||
private readonly WindowSystem _windowSystem;
|
||||
private bool _readFirstPage = false;
|
||||
|
||||
public event EventHandler? FinishedRegistration;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_windowSystem.RemoveWindow(this);
|
||||
}
|
||||
|
||||
public IntroUI(WindowSystem windowSystem, UIShared uiShared, Configuration pluginConfiguration,
|
||||
FileCacheManager fileCacheManager) : base("Mare Synchronos Setup")
|
||||
{
|
||||
_uiShared = uiShared;
|
||||
_pluginConfiguration = pluginConfiguration;
|
||||
_fileCacheManager = fileCacheManager;
|
||||
_windowSystem = windowSystem;
|
||||
|
||||
SizeConstraints = new WindowSizeConstraints()
|
||||
{
|
||||
MinimumSize = new(600, 400),
|
||||
MaximumSize = new(600, 2000)
|
||||
};
|
||||
|
||||
_windowSystem.AddWindow(this);
|
||||
IsOpen = true;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!IsOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_pluginConfiguration.AcceptedAgreement && !_readFirstPage)
|
||||
{
|
||||
ImGui.SetWindowFontScale(1.3f);
|
||||
ImGui.Text("Welcome to Mare Synchronos!");
|
||||
ImGui.SetWindowFontScale(1.0f);
|
||||
ImGui.Separator();
|
||||
UIShared.TextWrapped("Mare Synchronos is a plugin that will replicate your full current character state including all Penumbra mods to other whitelisted Mare Synchronos users. " +
|
||||
"Note that you will have to have Penumbra as well as Glamourer installed to use this plugin.");
|
||||
UIShared.TextWrapped("We will have to setup a few things first before you can start using this plugin. Click on next to continue.");
|
||||
|
||||
if (!_uiShared.DrawOtherPluginState()) return;
|
||||
ImGui.Separator();
|
||||
if (ImGui.Button("Next##toAgreement"))
|
||||
{
|
||||
_readFirstPage = true;
|
||||
}
|
||||
}
|
||||
else if (!_pluginConfiguration.AcceptedAgreement && _readFirstPage)
|
||||
{
|
||||
ImGui.SetWindowFontScale(1.3f);
|
||||
ImGui.Text("Agreement of Usage of Service");
|
||||
ImGui.SetWindowFontScale(1.0f);
|
||||
ImGui.Separator();
|
||||
ImGui.SetWindowFontScale(1.5f);
|
||||
string readThis = "READ THIS CAREFULLY";
|
||||
var textSize = ImGui.CalcTextSize(readThis);
|
||||
ImGui.SetCursorPosX(ImGui.GetWindowSize().X / 2 - textSize.X / 2);
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, readThis);
|
||||
ImGui.SetWindowFontScale(1.0f);
|
||||
ImGui.Separator();
|
||||
UIShared.TextWrapped("All of the mod files currently active on your character as well as your current character state will be uploaded to the service you registered yourself at automatically. " +
|
||||
"The plugin will exclusively upload the necessary mod files and not the whole mod.");
|
||||
UIShared.TextWrapped("If you are on a data capped internet connection, higher fees due to data usage depending on the amount of downloaded and uploaded mod files might occur. " +
|
||||
"Mod files will be compressed on up- and download to save on bandwidth usage. Due to varying up- and download speeds, changes in characters might not be visible immediately. " +
|
||||
"Files present on the service that already represent your active mod files will not be uploaded again.");
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
UIShared.TextWrapped("The mod files you are uploading are confidential and will not be distributed to parties other than the ones who are requesting the exact same mod files. " +
|
||||
"Please think about who you are going to whitelist since it is unavoidable that they will receive and locally cache the necessary mod files that you have currently in use. " +
|
||||
"Locally cached mod files will have arbitrary file names to discourage attempts at replicating the original mod.");
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
||||
UIShared.TextWrapped("The plugin creator tried their best to keep you secure. However, there is no guarantee for 100% security. Do not blindly add everyone to your whitelist.");
|
||||
ImGui.PopStyleColor();
|
||||
UIShared.TextWrapped("Mod files that are saved on the service will remain on the service as long as there are requests for the files from clients. " +
|
||||
"After a period of not being used, the mod files will be automatically deleted. " +
|
||||
"You will also be able to wipe all the files you have personally uploaded on request. " +
|
||||
"The service holds no information about which mod files belong to which mod.");
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
UIShared.TextWrapped("This service is provided as-is. In case of abuse, contact darkarchon#4313 on Discord or join the Mare Synchronos Discord. " +
|
||||
"To accept those conditions hold CTRL while clicking 'I agree'");
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.Button("I agree##toSetup"))
|
||||
{
|
||||
if (ImGui.GetIO().KeyCtrl)
|
||||
{
|
||||
_pluginConfiguration.AcceptedAgreement = true;
|
||||
_pluginConfiguration.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_pluginConfiguration.AcceptedAgreement && (string.IsNullOrEmpty(_pluginConfiguration.CacheFolder) || _pluginConfiguration.InitialScanComplete == false))
|
||||
{
|
||||
ImGui.SetWindowFontScale(1.3f);
|
||||
ImGui.Text("File Cache Setup");
|
||||
ImGui.SetWindowFontScale(1.0f);
|
||||
ImGui.Separator();
|
||||
UIShared.TextWrapped("To not unnecessary download files already present on your computer, Mare Synchronos will have to scan your Penumbra mod directory. " +
|
||||
"Additionally, a local cache folder must be set where Mare Synchronos will download its local file cache to. " +
|
||||
"Once the Cache Folder is set and the scan complete, this page will automatically forward to registration at a service.");
|
||||
UIShared.TextWrapped("Note: The initial scan, depending on the amount of mods you have, might take a while. Please wait until it is completed.");
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
||||
UIShared.TextWrapped("Warning: once past this step you should not delete the FileCache.db of Mare Synchronos in the Plugin Configurations folder of Dalamud. " +
|
||||
"Otherwise on the next launch a full re-scan of the file cache database will be initiated.");
|
||||
ImGui.PopStyleColor();
|
||||
_uiShared.DrawCacheDirectorySetting();
|
||||
|
||||
|
||||
if (!_fileCacheManager.IsScanRunning)
|
||||
{
|
||||
UIShared.TextWrapped("You can adjust how many parallel threads will be used for scanning. Mind that ultimately it will depend on the amount of mods, your disk speed and your CPU. " +
|
||||
"More is not necessarily better, the default of 10 should be fine for most cases.");
|
||||
_uiShared.DrawParallelScansSetting();
|
||||
|
||||
|
||||
if (ImGui.Button("Start Scan##startScan"))
|
||||
{
|
||||
_fileCacheManager.StartInitialScan();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_uiShared.DrawFileScanState();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.SetWindowFontScale(1.3f);
|
||||
ImGui.Text("Service registration");
|
||||
ImGui.SetWindowFontScale(1.0f);
|
||||
ImGui.Separator();
|
||||
if (_pluginConfiguration.ClientSecret.ContainsKey(_pluginConfiguration.ApiUri))
|
||||
{
|
||||
ImGui.Separator();
|
||||
UIShared.TextWrapped(_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri]);
|
||||
ImGui.Separator();
|
||||
ImGui.Button("Copy secret key to clipboard");
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
||||
UIShared.TextWrapped("This is the only time you will be able to see this key in the UI. You can copy it to make a backup somewhere.");
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.Separator();
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.ParsedGreen);
|
||||
UIShared.TextWrapped("You are now ready to go. Press Finish to finalize the settings and open the Mare Synchronos main UI.");
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.Separator();
|
||||
if (ImGui.Button("Finish##finishIntro"))
|
||||
{
|
||||
FinishedRegistration?.Invoke(null, EventArgs.Empty);
|
||||
IsOpen = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UIShared.TextWrapped("You will now have to register at a service. You can use the provided central service or pick a custom one. " +
|
||||
"There is no support for custom services from the plugin creator. Use at your own risk.");
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
UIShared.TextWrapped("On registration on a service the plugin will create and save a secret key to your plugin configuration. " +
|
||||
"Make a backup of your secret key. In case of loss, it cannot be restored. The secret key is your identification to the service " +
|
||||
"to verify who you are. It is directly tied to the UID you will be receiving. In case of loss, you will have to re-register an account.");
|
||||
UIShared.TextWrapped("Do not ever, under any circumstances, share your secret key to anyone! Likewise do not share your Mare Synchronos plugin configuration to anyone!");
|
||||
ImGui.PopStyleColor();
|
||||
_uiShared.DrawServiceSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
263
MareSynchronos/UI/PluginUI.cs
Normal file
263
MareSynchronos/UI/PluginUI.cs
Normal file
@@ -0,0 +1,263 @@
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Logging;
|
||||
using ImGuiNET;
|
||||
using MareSynchronos.WebAPI;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Dalamud.Configuration;
|
||||
using MareSynchronos.API;
|
||||
|
||||
namespace MareSynchronos.UI
|
||||
{
|
||||
class PluginUi : Window, IDisposable
|
||||
{
|
||||
private readonly Configuration _configuration;
|
||||
private readonly WindowSystem _windowSystem;
|
||||
private readonly ApiController _apiController;
|
||||
private readonly UIShared _uiShared;
|
||||
|
||||
public PluginUi(WindowSystem windowSystem,
|
||||
UIShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos Settings", ImGuiWindowFlags.None)
|
||||
{
|
||||
SizeConstraints = new WindowSizeConstraints()
|
||||
{
|
||||
MinimumSize = new(1000, 400),
|
||||
MaximumSize = new(1000, 2000),
|
||||
};
|
||||
|
||||
this._configuration = configuration;
|
||||
this._windowSystem = windowSystem;
|
||||
this._apiController = apiController;
|
||||
_uiShared = uiShared;
|
||||
windowSystem.AddWindow(this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_windowSystem.RemoveWindow(this);
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!IsOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_apiController.SecretKey != "-" && !_apiController.IsConnected && _apiController.ServerAlive)
|
||||
{
|
||||
if (ImGui.Button("Reset Secret Key"))
|
||||
{
|
||||
_configuration.ClientSecret.Clear();
|
||||
_configuration.Save();
|
||||
_apiController.RestartHeartbeat();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_uiShared.DrawOtherPluginState()) return;
|
||||
|
||||
DrawSettingsContent();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSettingsContent()
|
||||
{
|
||||
_uiShared.PrintServerState();
|
||||
ImGui.Separator();
|
||||
ImGui.SetWindowFontScale(1.2f);
|
||||
ImGui.Text("Your UID");
|
||||
ImGui.SameLine();
|
||||
if (_apiController.ServerAlive)
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.UID);
|
||||
ImGui.SameLine();
|
||||
ImGui.SetWindowFontScale(1.0f);
|
||||
if (ImGui.Button("Copy UID"))
|
||||
{
|
||||
ImGui.SetClipboardText(_apiController.UID);
|
||||
}
|
||||
ImGui.Text("Share this UID to other Mare users so they can add you to their whitelist.");
|
||||
ImGui.Separator();
|
||||
DrawWhiteListContent();
|
||||
DrawFileCacheSettings();
|
||||
DrawCurrentTransfers();
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, "No UID (Service unavailable)");
|
||||
ImGui.SetWindowFontScale(1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCurrentTransfers()
|
||||
{
|
||||
if (ImGui.TreeNode(
|
||||
$"Current Transfers"))
|
||||
{
|
||||
if (ImGui.BeginTable("TransfersTable", 2))
|
||||
{
|
||||
ImGui.TableSetupColumn(
|
||||
$"Uploads ({UIShared.ByteToKiB(_apiController.CurrentUploads.Sum(a => a.Value.Item1))} / {UIShared.ByteToKiB(_apiController.CurrentUploads.Sum(a => a.Value.Item2))})");
|
||||
ImGui.TableSetupColumn($"Downloads ({UIShared.ByteToKiB(_apiController.CurrentDownloads.Sum(a => a.Value.Item1))} / {UIShared.ByteToKiB(_apiController.CurrentDownloads.Sum(a => a.Value.Item2))})");
|
||||
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGui.BeginTable("UploadsTable", 3))
|
||||
{
|
||||
ImGui.TableSetupColumn("File");
|
||||
ImGui.TableSetupColumn("Uploaded");
|
||||
ImGui.TableSetupColumn("Size");
|
||||
ImGui.TableHeadersRow();
|
||||
foreach (var hash in _apiController.CurrentUploads.Keys)
|
||||
{
|
||||
var color = UIShared.UploadColor(_apiController.CurrentUploads[hash]);
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, color);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(hash);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(UIShared.ByteToKiB(_apiController.CurrentUploads[hash].Item1));
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(UIShared.ByteToKiB(_apiController.CurrentUploads[hash].Item2));
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.TableNextRow();
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGui.BeginTable("DownloadsTable", 3))
|
||||
{
|
||||
ImGui.TableSetupColumn("File");
|
||||
ImGui.TableSetupColumn("Downloaded");
|
||||
ImGui.TableSetupColumn("Size");
|
||||
ImGui.TableHeadersRow();
|
||||
foreach (var hash in _apiController.CurrentDownloads.Keys)
|
||||
{
|
||||
var color = UIShared.UploadColor(_apiController.CurrentDownloads[hash]);
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, color);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(hash);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(UIShared.ByteToKiB(_apiController.CurrentDownloads[hash].Item1));
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(UIShared.ByteToKiB(_apiController.CurrentDownloads[hash].Item2));
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.TableNextRow();
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawFileCacheSettings()
|
||||
{
|
||||
if (ImGui.TreeNode("File Cache Settings"))
|
||||
{
|
||||
_uiShared.DrawFileScanState();
|
||||
_uiShared.DrawCacheDirectorySetting();
|
||||
_uiShared.DrawParallelScansSetting();
|
||||
ImGui.TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawWhiteListContent()
|
||||
{
|
||||
if (!_apiController.ServerAlive) return;
|
||||
if (ImGui.TreeNode("Whitelist Configuration"))
|
||||
{
|
||||
if (ImGui.BeginTable("WhitelistTable", 6))
|
||||
{
|
||||
ImGui.TableSetupColumn("Pause", ImGuiTableColumnFlags.WidthFixed, 50);
|
||||
ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.WidthFixed, 110);
|
||||
ImGui.TableSetupColumn("Status", ImGuiTableColumnFlags.WidthFixed, 120);
|
||||
ImGui.TableSetupColumn("Paused", ImGuiTableColumnFlags.WidthFixed, 140);
|
||||
ImGui.TableSetupColumn("Comment", ImGuiTableColumnFlags.WidthFixed, 400);
|
||||
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 70);
|
||||
|
||||
ImGui.TableHeadersRow();
|
||||
foreach (var item in _apiController.WhitelistEntries.ToList())
|
||||
{
|
||||
ImGui.TableNextColumn();
|
||||
bool isPaused = item.IsPaused;
|
||||
if (ImGui.Checkbox("##paused" + item.OtherUID, ref isPaused))
|
||||
{
|
||||
_ = _apiController.SendWhitelistPauseChange(item.OtherUID, isPaused);
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextColored(
|
||||
UIShared.GetBoolColor(item.IsSynced && !item.IsPausedFromOthers && !item.IsPaused),
|
||||
item.OtherUID);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextColored(UIShared.GetBoolColor(item.IsSynced),
|
||||
!item.IsSynced ? "Has not added you" : "Whitelisted");
|
||||
ImGui.TableNextColumn();
|
||||
string pauseYou = item.IsPaused ? "You paused them" : "";
|
||||
string pauseThey = item.IsPausedFromOthers ? "They paused you" : "";
|
||||
string separator = (item.IsPaused && item.IsPausedFromOthers) ? Environment.NewLine : "";
|
||||
string entry = pauseYou + separator + pauseThey;
|
||||
ImGui.TextColored(UIShared.GetBoolColor(!item.IsPausedFromOthers && !item.IsPaused),
|
||||
string.IsNullOrEmpty(entry) ? "No" : entry);
|
||||
ImGui.TableNextColumn();
|
||||
string charComment = _configuration.UidComments.ContainsKey(item.OtherUID) ? _configuration.UidComments[item.OtherUID] : string.Empty;
|
||||
ImGui.SetNextItemWidth(400);
|
||||
if (ImGui.InputTextWithHint("##comment" + item.OtherUID, "Add your comment here (comments will not be synced)", ref charComment, 255))
|
||||
{
|
||||
_configuration.UidComments[item.OtherUID] = charComment;
|
||||
_configuration.Save();
|
||||
}
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGui.Button("Delete##" + item.OtherUID))
|
||||
{
|
||||
_ = _apiController.SendWhitelistRemoval(item.OtherUID);
|
||||
_apiController.WhitelistEntries.Remove(item);
|
||||
}
|
||||
|
||||
ImGui.TableNextRow();
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
|
||||
var whitelistEntry = tempDto.OtherUID;
|
||||
ImGui.SetNextItemWidth(200);
|
||||
if (ImGui.InputText("UID", ref whitelistEntry, 20))
|
||||
{
|
||||
tempDto.OtherUID = whitelistEntry;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Add to whitelist"))
|
||||
{
|
||||
if (_apiController.WhitelistEntries.All(w => w.OtherUID != tempDto.OtherUID))
|
||||
{
|
||||
_apiController.WhitelistEntries.Add(new WhitelistDto()
|
||||
{
|
||||
OtherUID = tempDto.OtherUID
|
||||
});
|
||||
|
||||
_ = _apiController.SendWhitelistAddition(tempDto.OtherUID);
|
||||
|
||||
tempDto.OtherUID = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
private WhitelistDto tempDto = new WhitelistDto() { OtherUID = string.Empty };
|
||||
}
|
||||
}
|
||||
184
MareSynchronos/UI/UIShared.cs
Normal file
184
MareSynchronos/UI/UIShared.cs
Normal file
@@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dalamud.Interface.Colors;
|
||||
using ImGuiNET;
|
||||
using MareSynchronos.FileCacheDB;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.WebAPI;
|
||||
|
||||
namespace MareSynchronos.UI
|
||||
{
|
||||
internal class UIShared
|
||||
{
|
||||
private readonly IpcManager _ipcManager;
|
||||
private readonly ApiController _apiController;
|
||||
private readonly FileCacheManager _fileCacheManager;
|
||||
private readonly Configuration _pluginConfiguration;
|
||||
|
||||
public UIShared(IpcManager ipcManager, ApiController apiController, FileCacheManager fileCacheManager, Configuration pluginConfiguration)
|
||||
{
|
||||
_ipcManager = ipcManager;
|
||||
_apiController = apiController;
|
||||
_fileCacheManager = fileCacheManager;
|
||||
_pluginConfiguration = pluginConfiguration;
|
||||
}
|
||||
|
||||
public bool DrawOtherPluginState()
|
||||
{
|
||||
var penumbraExists = _ipcManager.CheckPenumbraApi();
|
||||
var glamourerExists = _ipcManager.CheckGlamourerApi();
|
||||
|
||||
var penumbraColor = penumbraExists ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
|
||||
var glamourerColor = glamourerExists ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
|
||||
ImGui.Text("Penumbra:");
|
||||
ImGui.SameLine();
|
||||
ImGui.TextColored(penumbraColor, penumbraExists ? "Available" : "Unavailable");
|
||||
ImGui.SameLine();
|
||||
ImGui.Text("Glamourer:");
|
||||
ImGui.SameLine();
|
||||
ImGui.TextColored(glamourerColor, glamourerExists ? "Available" : "Unavailable");
|
||||
|
||||
if (!penumbraExists || !glamourerExists)
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, "You need to install both Penumbra and Glamourer and keep them up to date to use Mare Synchronos.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void DrawFileScanState()
|
||||
{
|
||||
ImGui.Text("File Scanner Status");
|
||||
if (_fileCacheManager.IsScanRunning)
|
||||
{
|
||||
ImGui.Text("Scan is running");
|
||||
ImGui.Text("Current Progress:");
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(_fileCacheManager.TotalFiles <= 0
|
||||
? "Collecting files"
|
||||
: $"Processing {_fileCacheManager.CurrentFileProgress} / {_fileCacheManager.TotalFiles} files");
|
||||
}
|
||||
else if (_fileCacheManager.TimeToNextScan.TotalSeconds == 0)
|
||||
{
|
||||
ImGui.Text("Scan not started");
|
||||
}
|
||||
{
|
||||
ImGui.Text("Next scan in " + _fileCacheManager.TimeToNextScan.ToString(@"mm\:ss") + " minutes");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintServerState()
|
||||
{
|
||||
ImGui.Text("Service status of " + (string.IsNullOrEmpty(_pluginConfiguration.ApiUri) ? ApiController.MainServer : _pluginConfiguration.ApiUri));
|
||||
ImGui.SameLine();
|
||||
var color = _apiController.ServerAlive ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
|
||||
ImGui.TextColored(color, _apiController.ServerAlive ? "Available" : "Unavailable");
|
||||
}
|
||||
|
||||
public static void TextWrapped(string text)
|
||||
{
|
||||
ImGui.PushTextWrapPos(0);
|
||||
ImGui.TextUnformatted(text);
|
||||
ImGui.PopTextWrapPos();
|
||||
}
|
||||
|
||||
public static Vector4 GetBoolColor(bool input) => input ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
|
||||
|
||||
public static Vector4 UploadColor((long, long) data) => data.Item1 == 0 ? ImGuiColors.DalamudGrey :
|
||||
data.Item1 == data.Item2 ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudYellow;
|
||||
|
||||
public static string ByteToKiB(long bytes) => (bytes / 1024.0).ToString("0.00") + " KiB";
|
||||
|
||||
private int _serverSelectionIndex = 0;
|
||||
|
||||
public void DrawServiceSelection()
|
||||
{
|
||||
string[] comboEntries = new[] { ApiController.MainServer, "Custom Service" };
|
||||
if (ImGui.BeginCombo("Service", comboEntries[_serverSelectionIndex]))
|
||||
{
|
||||
for (int n = 0; n < comboEntries.Length; n++)
|
||||
{
|
||||
bool isSelected = _serverSelectionIndex == n;
|
||||
if (ImGui.Selectable(comboEntries[n], isSelected))
|
||||
{
|
||||
_serverSelectionIndex = n;
|
||||
}
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
ImGui.SetItemDefaultFocus();
|
||||
}
|
||||
|
||||
bool useCustomService = _serverSelectionIndex != 0;
|
||||
|
||||
if (_apiController.UseCustomService != useCustomService)
|
||||
{
|
||||
_apiController.UseCustomService = useCustomService;
|
||||
_pluginConfiguration.Save();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
if (_apiController.UseCustomService)
|
||||
{
|
||||
string serviceAddress = _pluginConfiguration.ApiUri;
|
||||
if (ImGui.InputText("Service address", ref serviceAddress, 255))
|
||||
{
|
||||
if (_pluginConfiguration.ApiUri != serviceAddress)
|
||||
{
|
||||
_pluginConfiguration.ApiUri = serviceAddress;
|
||||
_apiController.RestartHeartbeat();
|
||||
_pluginConfiguration.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrintServerState();
|
||||
if (_apiController.ServerAlive)
|
||||
{
|
||||
if (ImGui.Button("Register"))
|
||||
{
|
||||
Task.WaitAll(_apiController.Register());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawCacheDirectorySetting()
|
||||
{
|
||||
var cacheDirectory = _pluginConfiguration.CacheFolder;
|
||||
if (ImGui.InputText("Cache Folder##cache", ref cacheDirectory, 255))
|
||||
{
|
||||
_pluginConfiguration.CacheFolder = cacheDirectory;
|
||||
if (!string.IsNullOrEmpty(_pluginConfiguration.CacheFolder) && Directory.Exists(_pluginConfiguration.CacheFolder))
|
||||
{
|
||||
_pluginConfiguration.Save();
|
||||
}
|
||||
}
|
||||
|
||||
if (!Directory.Exists(cacheDirectory))
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
UIShared.TextWrapped("The folder you selected does not exist. Please provide a valid path.");
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawParallelScansSetting()
|
||||
{
|
||||
var parallelScans = _pluginConfiguration.MaxParallelScan;
|
||||
if (ImGui.SliderInt("Parallel File Scans##parallelism", ref parallelScans, 1, 20))
|
||||
{
|
||||
_pluginConfiguration.MaxParallelScan = parallelScans;
|
||||
_pluginConfiguration.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user