mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 13:14:17 +01:00
Complete refactoring of most code, indiscriminate application of .editorconfig and general cleanup.
This commit is contained in:
parent
5332119a63
commit
a19ec226c5
84 changed files with 3168 additions and 1709 deletions
84
Penumbra/MigrateConfiguration.cs
Normal file
84
Penumbra/MigrateConfiguration.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Dalamud.Plugin;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Penumbra.Mod;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.Util;
|
||||
|
||||
namespace Penumbra
|
||||
{
|
||||
public static class MigrateConfiguration
|
||||
{
|
||||
public static void Version0To1( Configuration config )
|
||||
{
|
||||
if( config.Version != 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
config.ModDirectory = config.CurrentCollection;
|
||||
config.CurrentCollection = "Default";
|
||||
config.Version = 1;
|
||||
ResettleCollectionJson( config );
|
||||
}
|
||||
|
||||
private static void ResettleCollectionJson( Configuration config )
|
||||
{
|
||||
var collectionJson = new FileInfo( Path.Combine( config.ModDirectory, "collection.json" ) );
|
||||
if( !collectionJson.Exists )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var defaultCollection = new ModCollection();
|
||||
var defaultCollectionFile = defaultCollection.FileName();
|
||||
if( defaultCollectionFile.Exists )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var text = File.ReadAllText( collectionJson.FullName );
|
||||
var data = JArray.Parse( text );
|
||||
|
||||
var maxPriority = 0;
|
||||
foreach( var setting in data.Cast< JObject >() )
|
||||
{
|
||||
var modName = ( string )setting[ "FolderName" ]!;
|
||||
var enabled = ( bool )setting[ "Enabled" ]!;
|
||||
var priority = ( int )setting[ "Priority" ]!;
|
||||
var settings = setting[ "Settings" ]!.ToObject< Dictionary< string, int > >()
|
||||
?? setting[ "Conf" ]!.ToObject< Dictionary< string, int > >();
|
||||
|
||||
var save = new ModSettings()
|
||||
{
|
||||
Enabled = enabled,
|
||||
Priority = priority,
|
||||
Settings = settings!,
|
||||
};
|
||||
defaultCollection.Settings.Add( modName, save );
|
||||
maxPriority = Math.Max( maxPriority, priority );
|
||||
}
|
||||
|
||||
if( config.InvertModListOrder )
|
||||
{
|
||||
foreach( var setting in defaultCollection.Settings.Values )
|
||||
{
|
||||
setting.Priority = maxPriority - setting.Priority;
|
||||
}
|
||||
}
|
||||
|
||||
defaultCollection.Save( Service< DalamudPluginInterface >.Get() );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Could not migrate the old collection file to new collection files:\n{e}" );
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue