2018-10-05 23:10:39 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
2018-10-05 23:10:39 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application.Migration
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// helps facilitate the migration of configs from one version and or location
|
|
|
|
|
/// to another
|
|
|
|
|
/// </summary>
|
|
|
|
|
class ConfigurationMigration
|
|
|
|
|
{
|
2019-05-08 21:34:17 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// ensures required directories are created
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void CheckDirectories()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(Path.Join(Utilities.OperatingDirectory, "Plugins")))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.Join(Utilities.OperatingDirectory, "Plugins"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Path.Join(Utilities.OperatingDirectory, "Database")))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.Join(Utilities.OperatingDirectory, "Database"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Path.Join(Utilities.OperatingDirectory, "Log")))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.Join(Utilities.OperatingDirectory, "Log"));
|
|
|
|
|
}
|
2020-02-11 17:44:06 -05:00
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Path.Join(Utilities.OperatingDirectory, "Localization")))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.Join(Utilities.OperatingDirectory, "Localization"));
|
|
|
|
|
}
|
2019-05-08 21:34:17 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-05 23:10:39 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// moves existing configs from the root folder into a configs folder
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void MoveConfigFolder10518(ILogger log)
|
|
|
|
|
{
|
|
|
|
|
string currentDirectory = Utilities.OperatingDirectory;
|
|
|
|
|
|
|
|
|
|
// we don't want to do this for migrations or tests where the
|
|
|
|
|
// property isn't initialized or it's wrong
|
|
|
|
|
if (currentDirectory != null)
|
|
|
|
|
{
|
|
|
|
|
string configDirectory = Path.Join(currentDirectory, "Configuration");
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(configDirectory))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(configDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var configurationFiles = Directory.EnumerateFiles(currentDirectory, "*.json")
|
|
|
|
|
.Select(f => f.Split(Path.DirectorySeparatorChar).Last())
|
|
|
|
|
.Where(f => f.Count(c => c == '.') == 1);
|
|
|
|
|
|
|
|
|
|
foreach (var configFile in configurationFiles)
|
|
|
|
|
{
|
|
|
|
|
string destinationPath = Path.Join("Configuration", configFile);
|
|
|
|
|
if (!File.Exists(destinationPath))
|
|
|
|
|
{
|
|
|
|
|
File.Move(configFile, destinationPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-06 12:47:14 -04:00
|
|
|
|
|
|
|
|
|
if (!File.Exists(Path.Join("Database", "Database.db")) &&
|
|
|
|
|
File.Exists("Database.db"))
|
|
|
|
|
{
|
|
|
|
|
File.Move("Database.db", Path.Join("Database", "Database.db"));
|
|
|
|
|
}
|
2018-10-05 23:10:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-09 16:35:13 -05:00
|
|
|
|
|
|
|
|
|
public static void ModifyLogPath020919(SharedLibraryCore.Configuration.ServerConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
if (config.ManualLogPath.IsRemoteLog())
|
|
|
|
|
{
|
|
|
|
|
config.GameLogServerUrl = new Uri(config.ManualLogPath);
|
|
|
|
|
config.ManualLogPath = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-22 12:46:32 -04:00
|
|
|
|
|
|
|
|
|
public static void RemoveObsoletePlugins20210322()
|
|
|
|
|
{
|
2022-03-01 13:47:35 -05:00
|
|
|
|
var files = new[] {"StatsWeb.dll", "StatsWeb.Views.dll", "IW4ScriptCommands.dll"};
|
2021-03-22 12:46:32 -04:00
|
|
|
|
|
|
|
|
|
foreach (var file in files)
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Join(Utilities.OperatingDirectory, "Plugins", file);
|
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-05 23:10:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|