This commit is contained in:
Jose Conde
2025-09-29 16:02:00 +02:00
parent dc57da8136
commit 5e16f781b4
74 changed files with 1621 additions and 1856 deletions

View File

@@ -0,0 +1,64 @@
using ModVersionChecker.controls;
using ModVersionChecker.model;
using ModVersionChecker.repository.api.dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModVersionChecker.utils
{
public class InputControlsFactory
{
public static Control CreateControl(FieldResponse field, TypeConfig config, Boolean enabled = true)
{
var value = config?.ConfigValues != null && config.ConfigValues.ContainsKey(field.Name) ? config.ConfigValues[field.Name] : field.DefaultValue;
var directoryField = () =>
{
var textBox = new TextBox
{
Width = 300,
Text = value,
ReadOnly = true
};
var control = new TableLayoutPanel
{
AutoSize = true,
Dock = DockStyle.Fill,
ColumnCount = 2,
RowCount = 1,
ColumnStyles = { new ColumnStyle(SizeType.Percent, 80), new ColumnStyle(SizeType.Percent, 20) }
};
control.Controls.Add(textBox, 0, 0);
var browseButton = new Button { Text = "Browse", Width = 80, Enabled = enabled };
browseButton.Click += (s, e) =>
{
using (var folderDialog = new FolderBrowserDialog())
{
folderDialog.Description = $"Select directory for {field.Label}";
//folderDialog.SelectedPath = textBox.Text == "" ? Path.Combine(fs.Path) : textBox.Text;
if (folderDialog.ShowDialog() == DialogResult.OK)
{
string selectedDirectory = folderDialog.SelectedPath;
//string folderName = Path.GetFileName(selectedDirectory);
textBox.Text = selectedDirectory;
}
}
};
control.Controls.Add(browseButton, 1, 0);
return control;
};
return field. ControlType.ToLower() switch
{
"text" => new TextBox { Text = value, Width = 300, Enabled = enabled },
"number" => new NumericUpDown { Value = decimal.TryParse(value, out var num) ? num : 0, Width = 100, Enabled = enabled },
"checkbox" => new CheckBox { Checked = bool.TryParse(value, out var isChecked) && isChecked, AutoSize = true, Enabled = enabled },
"directory" => new DirectoryPickerControl { SelectedPath = value, Enabled = enabled },
_ => new TextBox { Text = value, Width = 300, Enabled = enabled }
};
}
}
}

View File

@@ -8,8 +8,10 @@ namespace ModVersionChecker.utils
{
public class TimeUtils
{
public static long GetUnixTimeMillis(DateTime? dateTime)
public static long GetUnixTimeMillis(DateTime? dateTime = null)
{
var a = DateTime.Now;
var b = DateTime.UtcNow;
DateTime dt = dateTime ?? DateTime.UtcNow;
return (long)(dt - new DateTime(1970, 1, 1)).TotalMilliseconds;
}

View File

@@ -1,4 +1,4 @@
using ModVersionChecker.data.model;
using ModVersionChecker.model;
using System.Text.Json;
using System.Text.RegularExpressions;
@@ -6,14 +6,14 @@ namespace ModVersionChecker.utils
{
public static class VersionUtils
{
public static string GetCurrentVersion(AppConfig app, FsModPathConfig config)
public static string GetCurrentVersion(App app, TypeConfig typeConfig)
{
var versionConfig = app.FsFields;
var packageName = versionConfig["msfs2024"]["package"];
var fsPath = config.Path;
var fsFile = config.File;
var fsFileType = config.FileType;
var fsKey = config.Key;
var versionConfig = app.Fields;
var packageName = versionConfig["package"];
var fsPath = typeConfig.ConfigValues.GetValueOrDefault("path", "");
var fsFile = typeConfig.ConfigValues.GetValueOrDefault("filename");
var fsFileType = typeConfig.ConfigValues.GetValueOrDefault("filetype", "");
var fsKey = typeConfig.ConfigValues.GetValueOrDefault("jsonkey", "");
var filePath = Path.GetFullPath(Path.Combine(fsPath, packageName, fsFile));