This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c9254d
commit bb22579
Showing
13 changed files
with
883 additions
and
485 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
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,77 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
using CheapLoc; | ||
using Dalamud.Game.Command; | ||
using Dalamud.Plugin; | ||
using Dalamud.Plugin.Services; | ||
|
||
namespace NeatNoter.Localization; | ||
|
||
public class LegacyLoc | ||
{ | ||
private readonly DalamudPluginInterface pluginInterface; | ||
private readonly ICommandManager commandManager; | ||
private readonly string pluginName; | ||
private readonly Assembly assembly; | ||
|
||
public LegacyLoc(DalamudPluginInterface pluginInterface, ICommandManager commandManager) | ||
{ | ||
this.pluginInterface = pluginInterface; | ||
this.commandManager = commandManager; | ||
this.assembly = Assembly.GetCallingAssembly(); | ||
this.pluginName = this.assembly.GetName().Name ?? string.Empty; | ||
this.SetLanguage(this.pluginInterface.UiLanguage); | ||
this.pluginInterface.LanguageChanged += this.LanguageChanged; | ||
this.commandManager.AddHandler( | ||
"/" + this.pluginName.ToLower() + "exloc", | ||
new CommandInfo(this.ExportLocalizable) | ||
{ | ||
ShowInHelp = false, | ||
}); | ||
} | ||
|
||
public void SetLanguage(string languageCode) | ||
{ | ||
if (!string.IsNullOrEmpty(languageCode) && languageCode != "en") | ||
{ | ||
try | ||
{ | ||
string locData; | ||
var resourceFile = $"{this.pluginName}.{this.pluginName}.Resource.translation.{languageCode}.json"; | ||
var resourceStream = this.assembly.GetManifestResourceStream(resourceFile); | ||
using (var reader = new StreamReader(resourceStream ?? throw new InvalidOperationException())) | ||
{ | ||
locData = reader.ReadToEnd(); | ||
} | ||
|
||
Loc.Setup(locData, this.assembly); | ||
} | ||
catch (Exception) | ||
{ | ||
Loc.SetupWithFallbacks(this.assembly); | ||
} | ||
} | ||
else | ||
{ | ||
Loc.SetupWithFallbacks(this.assembly); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
this.pluginInterface.LanguageChanged -= this.LanguageChanged; | ||
this.commandManager.RemoveHandler("/" + this.pluginName.ToLower() + "exloc"); | ||
} | ||
|
||
private void ExportLocalizable(string command, string args) | ||
{ | ||
Loc.ExportLocalizableForAssembly(this.assembly); | ||
} | ||
|
||
private void LanguageChanged(string langCode) | ||
{ | ||
this.SetLanguage(langCode); | ||
} | ||
} |
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,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using Dalamud.DrunkenToad.Helpers; | ||
using Dalamud.Logging; | ||
|
||
namespace NeatNoter; | ||
|
||
public class BackupManager | ||
{ | ||
private readonly string dataPath; | ||
|
||
public BackupManager(string pluginFolder) | ||
{ | ||
this.dataPath = pluginFolder + "/data/"; | ||
} | ||
|
||
public void CreateBackup(string prefix = "") | ||
{ | ||
try | ||
{ | ||
var backupDir = $"{this.dataPath}{prefix}{UnixTimestampHelper.CurrentTime()}/"; | ||
Directory.CreateDirectory(backupDir); | ||
var files = Directory.GetFiles(this.dataPath); | ||
foreach (var file in files) | ||
{ | ||
var fileName = Path.GetFileName(file); | ||
File.Copy(this.dataPath + fileName, backupDir + fileName, true); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
PluginLog.LogError(ex, "Failed to create backup."); | ||
} | ||
} | ||
|
||
public void DeleteBackups(int max) | ||
{ | ||
// don't delete everything | ||
if (max == 0) | ||
{ | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
// loop through directories and get those without prefix | ||
var dirs = Directory.GetDirectories(this.dataPath); | ||
var dirNames = new List<long>(); | ||
foreach (var dir in dirs) | ||
{ | ||
try | ||
{ | ||
var dirName = new DirectoryInfo(dir).Name; | ||
if (dirName.Any(char.IsLetter)) | ||
{ | ||
continue; | ||
} | ||
|
||
dirNames.Add(Convert.ToInt64(dirName)); | ||
} | ||
catch (Exception) | ||
{ | ||
// ignored | ||
} | ||
} | ||
|
||
// if don't exceed max then out | ||
if (dirs.Length <= max) | ||
{ | ||
return; | ||
} | ||
|
||
dirNames.Sort(); | ||
Directory.Delete(this.dataPath + dirNames.First(), true); | ||
this.DeleteBackups(max); | ||
} | ||
catch (Exception ex) | ||
{ | ||
PluginLog.LogError(ex, "Failed to delete backup."); | ||
} | ||
} | ||
} |
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,19 @@ | ||
namespace NeatNoter; | ||
|
||
public class BaseRepository : Repository | ||
{ | ||
protected BaseRepository(string pluginFolder) | ||
: base(pluginFolder) | ||
{ | ||
} | ||
|
||
public int GetSchemaVersion() | ||
{ | ||
return this.GetVersion(); | ||
} | ||
|
||
public void SetSchemaVersion(int version) | ||
{ | ||
this.SetVersion(version); | ||
} | ||
} |
Oops, something went wrong.