prevent secret key input if it's not 40 characters long, check for directory existence in intro ui, check for illegal characters in path

This commit is contained in:
Stanley Dimant
2022-07-17 02:38:56 +02:00
parent acdc1502b6
commit 51366c95a7
4 changed files with 32 additions and 11 deletions

View File

@@ -358,6 +358,7 @@ namespace MareSynchronos.Managers
StartWatchers(); StartWatchers();
StartInitialScan(); StartInitialScan();
} }
private void StopWatchersAndScan() private void StopWatchersAndScan()
{ {
_cacheDirWatcher?.Dispose(); _cacheDirWatcher?.Dispose();

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors></Authors> <Authors></Authors>
<Company></Company> <Company></Company>
<Version>0.1.12.0</Version> <Version>0.1.13.0</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl> <PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.IO;
using System.Numerics; using System.Numerics;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
@@ -105,7 +106,10 @@ namespace MareSynchronos.UI
} }
} }
} }
else if (_pluginConfiguration.AcceptedAgreement && (string.IsNullOrEmpty(_pluginConfiguration.CacheFolder) || _pluginConfiguration.InitialScanComplete == false)) else if (_pluginConfiguration.AcceptedAgreement
&& (string.IsNullOrEmpty(_pluginConfiguration.CacheFolder)
|| _pluginConfiguration.InitialScanComplete == false
|| !Directory.Exists(_pluginConfiguration.CacheFolder)))
{ {
if (_uiShared.UidFontBuilt) ImGui.PushFont(_uiShared.UidFont); if (_uiShared.UidFontBuilt) ImGui.PushFont(_uiShared.UidFont);
ImGui.TextUnformatted("File Cache Setup"); ImGui.TextUnformatted("File Cache Setup");

View File

@@ -3,6 +3,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
@@ -247,6 +248,7 @@ namespace MareSynchronos.UI
private string _customServerUri = ""; private string _customServerUri = "";
private bool _enterSecretKey = false; private bool _enterSecretKey = false;
private bool _cacheDirectoryHasOtherFilesThanCache = false; private bool _cacheDirectoryHasOtherFilesThanCache = false;
private bool _cacheDirectoryHasIllegalCharacter = false;
public void DrawServiceSelection(Action? callBackOnExit = null, bool isIntroUi = false) public void DrawServiceSelection(Action? callBackOnExit = null, bool isIntroUi = false)
{ {
@@ -349,15 +351,23 @@ namespace MareSynchronos.UI
ImGui.SetNextItemWidth(400); ImGui.SetNextItemWidth(400);
ImGui.InputText("Enter Secret Key", ref _secretKey, 255); ImGui.InputText("Enter Secret Key", ref _secretKey, 255);
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button("Save")) if (_secretKey.Length > 0 && _secretKey.Length != 40)
{ {
_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri] = _secretKey; ColorTextWrapped("Your secret key must be exactly 40 characters long. If try to enter your UID here, this is incorrect." +
_pluginConfiguration.Save(); " If you have lost your secret key, you will need to create a new account.", ImGuiColors.DalamudRed);
_secretKey = string.Empty; }
Task.Run(_apiController.CreateConnections); else
ShowClientSecret = false; {
_enterSecretKey = false; if (ImGui.Button("Save"))
callBackOnExit?.Invoke(); {
_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri] = _secretKey;
_pluginConfiguration.Save();
_secretKey = string.Empty;
Task.Run(_apiController.CreateConnections);
ShowClientSecret = false;
_enterSecretKey = false;
callBackOnExit?.Invoke();
}
} }
} }
} }
@@ -400,12 +410,14 @@ namespace MareSynchronos.UI
_isPenumbraDirectory = path.ToLower() == _ipcManager.PenumbraModDirectory()?.ToLower(); _isPenumbraDirectory = path.ToLower() == _ipcManager.PenumbraModDirectory()?.ToLower();
_isDirectoryWritable = IsDirectoryWritable(path); _isDirectoryWritable = IsDirectoryWritable(path);
_cacheDirectoryHasOtherFilesThanCache = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Any(f => new FileInfo(f).Name.Length != 40); _cacheDirectoryHasOtherFilesThanCache = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Any(f => new FileInfo(f).Name.Length != 40);
_cacheDirectoryHasIllegalCharacter = Regex.IsMatch(path, @"^(\w:\\(\w|\\)*|\/(\w|\/)*)");
if (!string.IsNullOrEmpty(path) if (!string.IsNullOrEmpty(path)
&& Directory.Exists(path) && Directory.Exists(path)
&& _isDirectoryWritable && _isDirectoryWritable
&& !_isPenumbraDirectory && !_isPenumbraDirectory
&& !_cacheDirectoryHasOtherFilesThanCache) && !_cacheDirectoryHasOtherFilesThanCache
&& !_cacheDirectoryHasIllegalCharacter)
{ {
_pluginConfiguration.CacheFolder = path; _pluginConfiguration.CacheFolder = path;
_pluginConfiguration.Save(); _pluginConfiguration.Save();
@@ -426,6 +438,10 @@ namespace MareSynchronos.UI
else if (_cacheDirectoryHasOtherFilesThanCache) else if (_cacheDirectoryHasOtherFilesThanCache)
{ {
ColorTextWrapped("Your selected directory has files inside that are not Mare related. Use an empty directory or a previous Mare cache directory only.", ImGuiColors.DalamudRed); ColorTextWrapped("Your selected directory has files inside that are not Mare related. Use an empty directory or a previous Mare cache directory only.", ImGuiColors.DalamudRed);
} else if (_cacheDirectoryHasIllegalCharacter)
{
ColorTextWrapped("Your selected directory contains illegal characters unreadable by FFXIV. " +
"Restrict yourself to latin letters (A-Z), underscores (_) and arabic numbers (0-9).", ImGuiColors.DalamudRed);
} }
int maxCacheSize = _pluginConfiguration.MaxLocalCacheInGiB; int maxCacheSize = _pluginConfiguration.MaxLocalCacheInGiB;