Skip to content

Commit

Permalink
Config Fix
Browse files Browse the repository at this point in the history
So the IniParser repo has some annoying weird thing like It wont return the actual type

I actually modified it and also added support by Int search other than the string

I already did a PR check below:
rickyah/ini-parser#248
  • Loading branch information
IchimakiKasura committed Mar 2, 2023
1 parent 65f4559 commit bacec43
Show file tree
Hide file tree
Showing 10 changed files with 1,019 additions and 69 deletions.
67 changes: 30 additions & 37 deletions Launcher DL/Core/Configuration/Config.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
using DLLanguages.Pick;
using static Launcher_DL.Core.Configuration.CONFIG_STR;

namespace Launcher_DL.Core.Configuration;

public class DefaultConfig
{
public string background = "background.png";
public string DefaultOutput = "output";
public string BrowserCookie = "chrome";
public string background = CONFIG_DEFAULT_BACKGROUND;
public string DefaultOutput = CONFIG_DEFAULT_OUTPUT;
public string BrowserCookie = CONFIG_DEFAULT_COOKIE;

public Color backgroundColor = ClrConv("#FF161438");
public Color backgroundGlow = ClrConv("#FF7DB5FF");
public Color backgroundColor = ClrConv(CONFIG_DEFAULT_BACKGROUND_COLOR);
public Color backgroundGlow = ClrConv(CONFIG_DEFAULT_BACKGROUND_GLOW);

public bool ShowSystemOutput = true;
public bool EnablePlaylist = true;
public bool EpicAnimations = true;
public bool AllowCookies = false;
public bool ShowSystemOutput = CONFIG_DEFAULT_SYSTEM_OUTPUT;
public bool EnablePlaylist = CONFIG_DEFAULT_PLAYLIST;
public bool EpicAnimations = CONFIG_DEFAULT_ANIMATIONS;
public bool AllowCookies = CONFIG_DEFAULT_COOKIES;

public int DefaultFileTypeOnStartUp = 0;
public int DefaultFileTypeOnStartUp = CONFIG_DEFAULT_FILE_TYPE;
public LanguageName Language = 0;
}

public class Config
{
static bool error = false;
static DefaultConfig DefaultConfiguration;
public static DefaultConfig ReadConfigINI(string Name = "Config.ini")
public static DefaultConfig ReadConfigINI()
{
FileIniDataParser parser = new();
string ConfigString = File.ReadAllText(CONFIG_NAME);
IniDataParser parser = new();
DefaultConfiguration = new();
IniData Data = parser.ReadFile(Name);
IniData Data = parser.Parse(ConfigString);

string LanguageCheck = Data["App"]["Language"];
string LanguageCheck = Data[CONFIG_SECTION_APP][CONFIG_LANGUAGE];

switch(LanguageCheck.ToLower())
{
Expand All @@ -41,20 +43,17 @@ public static DefaultConfig ReadConfigINI(string Name = "Config.ini")
case "bruh": DefaultConfiguration.Language = LanguageName.bruh; break;
}

// HOLY FUCKING SHIT I JUST NEEDED TO ADD THE "REF" BECAUSE ITS JUST PASSING ITS VALUE
// SO IF I TRIED TO CHANGE THE VALUE FROM THAT METHOD IT WONT CHANGE UNLESS I REFERENCE IT
// THANKS TO THIS SAVIOR:
// https://codeeasy.io/lesson/passing_parameters_to_functions
CheckError(ref DefaultConfiguration.background, Data["Background"]["backgroundName"],"backgroundName");
CheckError(ref DefaultConfiguration.backgroundColor, Data["Background"]["backgroundColor"],"backgroundColor");
CheckError(ref DefaultConfiguration.backgroundGlow, Data["Background"]["backgroundGlowColor"],"backgroundGlowColor");
CheckError(ref DefaultConfiguration.DefaultOutput, Data["File"]["DefaultOutput"],"DefaultOutput");
CheckError(ref DefaultConfiguration.ShowSystemOutput, Data["Console"]["ShowSystemOutput"],"ShowSystemOutput");
CheckError(ref DefaultConfiguration.DefaultFileTypeOnStartUp, Data["DropDown"]["DefaultFileTypeOnStartUp"],"DefaultFileTypeOnStartUp");
CheckError(ref DefaultConfiguration.EnablePlaylist, Data["Playlist"]["EnablePlaylist"],"EnablePlaylist");
CheckError(ref DefaultConfiguration.EpicAnimations, Data["graphics"]["EpicAnimations"],"EpicAnimations");
CheckError(ref DefaultConfiguration.AllowCookies, Data["Cookies"]["AllowCookies"],"AllowCookies");
CheckError(ref DefaultConfiguration.BrowserCookie, Data["Cookies"]["BrowserCookie"],"BrowserCookie");
// I am pleased on this
CheckError(ref DefaultConfiguration.background, Data[CONFIG_SECTION_BACKROUND][0], CONFIG_BACKGROUND_NAME);
CheckError(ref DefaultConfiguration.backgroundColor, Data[CONFIG_SECTION_BACKROUND][1], CONFIG_BACKGROUND_COLOR);
CheckError(ref DefaultConfiguration.backgroundGlow, Data[CONFIG_SECTION_BACKROUND][2], CONFIG_BACKGROUND_GLOW);
CheckError(ref DefaultConfiguration.AllowCookies, Data[CONFIG_SECTION_COOKIES][0], CONFIG_ALLOW_COOKIES);
CheckError(ref DefaultConfiguration.BrowserCookie, Data[CONFIG_SECTION_COOKIES][1], CONFIG_BROWSER_COOKIES);
CheckError(ref DefaultConfiguration.DefaultOutput, Data[CONFIG_SECTION_FILE][0], CONFIG_OUTPUT);
CheckError(ref DefaultConfiguration.ShowSystemOutput, Data[CONFIG_SECTION_CONSOLE][0], CONFIG_SYSTEM_OUTPUT);
CheckError(ref DefaultConfiguration.DefaultFileTypeOnStartUp, Data[CONFIG_SECTION_DROPDOWN][0], CONFIG_FILE_TYPE);
CheckError(ref DefaultConfiguration.EnablePlaylist, Data[CONFIG_SECTION_PLAYLIST][0], CONFIG_ENABLE_PLAYLIST);
CheckError(ref DefaultConfiguration.EpicAnimations, Data[CONFIG_SECTION_GRAPHICS][0], CONFIG_ANIMATIONS);

if(!error)
{
Expand All @@ -73,22 +72,16 @@ public static DefaultConfig ReadConfigINI(string Name = "Config.ini")
return DefaultConfiguration;
}

private static void CheckError<T>(ref T a,dynamic b,string c)
private static void CheckError<T>(ref T a, dynamic b, string c)
{
#if DEBUG
ConsoleDebug.LoadingConfig(a,b,c);
#endif

try
{
switch(a.GetType().ToString())
{
case "System.String": a = b; break;
case "System.Int32": a = int.Parse(b); break;
case "System.Windows.Media.Color": a = ClrConv(b); break;
case "System.Boolean": a = bool.Parse(b); break;
}

if(a.GetType().ToString().Contains(CONFIG_COLOR_CONTAINS)) a = ClrConv(b);
else a = b;
} catch(Exception e)
{
error = true;
Expand Down
11 changes: 3 additions & 8 deletions Launcher DL/Core/Debug/ConsoleDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,13 @@ public static void LoadConfigDone(bool isFailed)
}

// goddamn it I got lazy naming these parameters
public static void LoadingConfig(dynamic a, dynamic b, string c)
public static void LoadingConfig<T>(T a, dynamic b, string c)
{
Console.Write($"Loading {c}");
try
{
switch(a.GetType().ToString())
{
case "System.String": a = b; break;
case "System.Int32": a = int.Parse(b); break;
case "System.Windows.Media.Color": a = ClrConv(b); break;
case "System.Boolean": a = bool.Parse(b); break;
}
if(a.GetType().ToString().Contains("System.Windows.Media.Color")) a = ClrConv(b);
else a = b;
Console.SetCursorPosition(34,4 + count);
Console.Write($"\x1b[32mLOADED! = {b}\x1b[0m\n");
} catch
Expand Down
36 changes: 16 additions & 20 deletions Launcher DL/Core/Windows/WindowsComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,25 @@ await Task.Run(()=>{
}
}

// why does the Format combobox doesnt turn to bright red its just a dim
// unlike the others.
public static void FreezeComponents(bool Freeze)
{
buttonFileFormat.IsEnabled = true;
buttonDownload.IsEnabled = true;
buttonUpdate.IsEnabled = true;
buttonOpenFile.IsEnabled = true;
textBoxLink.IsEnabled = true;
textBoxName.IsEnabled = true;
comboBoxType.IsEnabled = true;
comboBoxFormat.IsEnabled = true;
UIElement[] ControlLists =
{
buttonFileFormat,
buttonDownload,
buttonUpdate,
buttonOpenFile,
textBoxLink,
textBoxName,
comboBoxType,
comboBoxFormat
};

foreach(UIElement CL in ControlLists)
CL.IsEnabled = true;

if(Freeze)
{
buttonFileFormat.IsEnabled = false;
buttonDownload.IsEnabled = false;
buttonUpdate.IsEnabled = false;
buttonOpenFile.IsEnabled = false;
textBoxLink.IsEnabled = false;
textBoxName.IsEnabled = false;
comboBoxType.IsEnabled = false;
comboBoxFormat.IsEnabled = false;
}
foreach(UIElement CL in ControlLists)
CL.IsEnabled = false;
}
}
2 changes: 1 addition & 1 deletion Launcher DL/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura>
<IncludeAssemblies>
INIFileParser
IniParser
</IncludeAssemblies>
</Costura>
</Weavers>
6 changes: 5 additions & 1 deletion Launcher DL/Launcher DL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<AssemblyName>uVad</AssemblyName>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<NoWarn>NU1701,CS8981,NU1503</NoWarn>
<AllowedReferenceRelatedFileExtensions>none</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -57,7 +58,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>compile; runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ini-parser" Version="2.5.2" />

<Reference Include="IniParser">
<HintPath>./ini-parser [modified]/IniParser.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Launcher DL/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public MainWindow()

buttonOpenFile.Click += delegate
{
console.AddFormattedText("<%20>Test");
WindowsComponents.FreezeComponents(false);
console.AddFormattedText("<%20>UNFREEZE!");
};
}
}
Binary file added Launcher DL/ini-parser [modified]/IniParser.dll
Binary file not shown.
Loading

0 comments on commit bacec43

Please sign in to comment.