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();
StartInitialScan();
}
private void StopWatchersAndScan()
{
_cacheDirWatcher?.Dispose();

View File

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

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Numerics;
using Dalamud.Interface.Colors;
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);
ImGui.TextUnformatted("File Cache Setup");

View File

@@ -3,6 +3,7 @@ using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
@@ -247,6 +248,7 @@ namespace MareSynchronos.UI
private string _customServerUri = "";
private bool _enterSecretKey = false;
private bool _cacheDirectoryHasOtherFilesThanCache = false;
private bool _cacheDirectoryHasIllegalCharacter = false;
public void DrawServiceSelection(Action? callBackOnExit = null, bool isIntroUi = false)
{
@@ -349,6 +351,13 @@ namespace MareSynchronos.UI
ImGui.SetNextItemWidth(400);
ImGui.InputText("Enter Secret Key", ref _secretKey, 255);
ImGui.SameLine();
if (_secretKey.Length > 0 && _secretKey.Length != 40)
{
ColorTextWrapped("Your secret key must be exactly 40 characters long. If try to enter your UID here, this is incorrect." +
" If you have lost your secret key, you will need to create a new account.", ImGuiColors.DalamudRed);
}
else
{
if (ImGui.Button("Save"))
{
_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri] = _secretKey;
@@ -361,6 +370,7 @@ namespace MareSynchronos.UI
}
}
}
}
private string _secretKey = "";
@@ -400,12 +410,14 @@ namespace MareSynchronos.UI
_isPenumbraDirectory = path.ToLower() == _ipcManager.PenumbraModDirectory()?.ToLower();
_isDirectoryWritable = IsDirectoryWritable(path);
_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)
&& Directory.Exists(path)
&& _isDirectoryWritable
&& !_isPenumbraDirectory
&& !_cacheDirectoryHasOtherFilesThanCache)
&& !_cacheDirectoryHasOtherFilesThanCache
&& !_cacheDirectoryHasIllegalCharacter)
{
_pluginConfiguration.CacheFolder = path;
_pluginConfiguration.Save();
@@ -426,6 +438,10 @@ namespace MareSynchronos.UI
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);
} 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;