Skip to content

Commit

Permalink
Added and fixed version checker for Mod compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
BigSpice committed Jan 20, 2024
1 parent 9366a9f commit 2f885f9
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 42 deletions.
Binary file modified VTOL_2.0.0/.vs/VTOL/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
45 changes: 25 additions & 20 deletions VTOL_2.0.0/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,47 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VTOL"
xmlns:Pages="clr-namespace:VTOL.Pages"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:parallax="clr-namespace:Parallax.WPF.Controls;assembly=Parallax.WPF"
xmlns:properties="clr-namespace:VTOL.Resources.Languages"
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"

xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"

xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:parallax="clr-namespace:Parallax.WPF.Controls;assembly=Parallax.WPF"
xmlns:properties="clr-namespace:VTOL.Resources.Languages"
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol" x:Name="Main_Win_Control" x:Class="VTOL.MainWindow"
UseLayoutRounding="True"
RenderOptions.BitmapScalingMode="HighQuality"
SnapsToDevicePixels="True"
RenderOptions.ClearTypeHint="Enabled"
mc:Ignorable="d"
Title="MainWindow"
ResizeMode="CanMinimize"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="True"
AllowDrop="True"
GotFocus="Main_Win_Control_GotFocus"
LostFocus="Main_Win_Control_LostFocus"
Deactivated="Main_Win_Control_Deactivated"
Activated="Main_Win_Control_Activated"
Closed="Main_Win_Control_Closed"
StateChanged="Main_Win_Control_StateChanged"
Loaded="Main_Win_Control_Loaded"
Closing="Main_Win_Control_Closing"
BorderBrush="#B27F7F7F"
BorderThickness="1,1,1,1"
SizeToContent="WidthAndHeight"

Title="MainWindow" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" AllowDrop="True" GotFocus="Main_Win_Control_GotFocus" LostFocus="Main_Win_Control_LostFocus" Deactivated="Main_Win_Control_Deactivated" Activated="Main_Win_Control_Activated" Closed="Main_Win_Control_Closed" StateChanged="Main_Win_Control_StateChanged" Loaded="Main_Win_Control_Loaded" Closing="Main_Win_Control_Closing" BorderBrush="#B27F7F7F" BorderThickness="1,1,1,1"

>

<Window.Resources>

<ScaleTransform x:Key="windowScaleTransform" ScaleX="0.5" ScaleY="0.5" />

<Storyboard x:Key="FadeInOut">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever"/>
</Storyboard>
<SolidColorBrush x:Key="Button_HOVER" Color="#FF2C4C4C" />
<ScaleTransform x:Key="windowScaleTransform" ScaleX="0.5" ScaleY="0.5" />

<Style TargetType="Image">

<Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality" />
</Style>


<ControlTemplate x:Key="ButtonControlTemplate1" TargetType="{x:Type Button}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" CornerRadius="20">
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
Expand Down Expand Up @@ -314,11 +323,7 @@
/>
<ui:NavigationSeparator />

<ui:NavigationItem x:Name="Skins"
Content="{x:Static properties:Language.MainWindow_Skins}"
Icon="InkStroke20" FontSize="10" PageType="{x:Type Pages:Page_Skins}" ClickMode="Press"
/>
<ui:NavigationSeparator />


<ui:NavigationItem x:Name="Server"
Content="{x:Static properties:Language.MainWindow_Server}"
Expand Down
11 changes: 8 additions & 3 deletions VTOL_2.0.0/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public partial class MainWindow : Window

public bool Is_Focused = true;
// public List<string> Current_Installed_Mods = new List<string>();
public HashSet<string> Current_Installed_Mods = new HashSet<string>();
public HashSet<GENERAL_MOD> Current_Installed_Mods = new HashSet<GENERAL_MOD>();

bool failed_folder = false;
public bool minimize_to_tray = false;
Expand All @@ -90,10 +90,15 @@ public partial class MainWindow : Window
// Copied from dwmapi.h


public class GENERAL_MOD
{
public string Name { get; set; }
public string Version { get; set; }
public string Author { get; set; }
}



public enum DWMWINDOWATTRIBUTE
public enum DWMWINDOWATTRIBUTE
{
DWMWA_WINDOW_CORNER_PREFERENCE = 33
}
Expand Down
4 changes: 2 additions & 2 deletions VTOL_2.0.0/Pages/Page_Home.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
BlurRadius="4"/>
</TextBlock.Effect>
</TextBlock>
<Image Source="/Resources/Icons/Main_UI/northstar_icon_ZfV_icon.png" Width="69" RenderTransformOrigin="0.5,0.5" >
<Image x:Name="HoldImage" Source="/Resources/Icons/Main_UI/northstar_icon_ZfV_icon.png" Width="69" RenderTransformOrigin="0.5,0.5" >
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.95"/>
Expand All @@ -166,7 +166,7 @@

</DockPanel>

<DockPanel Margin="38,203,0,409" Grid.RowSpan="1" Grid.ColumnSpan="1" Grid.Column="0" Grid.Row="0" LastChildFill="False" HorizontalAlignment="Left" Width="1002">
<DockPanel x:Name="Nameplate_Dock" Margin="38,203,0,409" Grid.RowSpan="1" Grid.ColumnSpan="1" Grid.Column="0" Grid.Row="0" LastChildFill="False" HorizontalAlignment="Left" Width="1002">
<TextBlock TextWrapping="Wrap" Text="A" Width="17" Foreground="White" FontSize="22" FontFamily="Segoe UI" DockPanel.Dock="Left" Margin="0.4,0,2,0" Height="32" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
Expand Down
10 changes: 8 additions & 2 deletions VTOL_2.0.0/Pages/Page_Home.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3799,14 +3799,20 @@ private void Unpack_To_Location(string Target_Zip, string Destination_Zip)
{
unpack_flg = false;
string searchPattern = @"Northstar.*";
string baseFolderPath = Path.Combine(Current_Install_Folder, User_Settings_Vars.Profile_Path, @"packages\");
string baseFolderPath = Path.Combine(Current_Install_Folder, User_Settings_Vars.Profile_Path);

string[] matchingFolders = Directory.GetDirectories(baseFolderPath, searchPattern, SearchOption.AllDirectories);


foreach (string folderPath in matchingFolders)
{
TryDeleteDirectory(folderPath, true);
if (Directory.Exists(folderPath))
{
MessageBox.Show(folderPath);

TryDeleteDirectory(folderPath, true);

}
}


Expand Down
50 changes: 39 additions & 11 deletions VTOL_2.0.0/Pages/Page_Mods.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using VTOL.Advocate.Conversion.JSON;
using static VTOL.MainWindow;
using static VTOL.Pages.Page_Profiles;
using Path = System.IO.Path;

Expand Down Expand Up @@ -241,7 +242,7 @@ public class NORTHSTARCOMPATIBLE_MOD
public bool IsValidandinstalled { get; set; }
public bool Has_Valid_Mod { get; set; }

public bool Namespace { get; set; }
public string Namespace { get; set; }

}

Expand Down Expand Up @@ -308,9 +309,10 @@ public List<NORTHSTARCOMPATIBLE_MOD> READ_UPDATE_MOD_LIST(DirectoryInfo[] modsTo
if (dirInfo.Exists)
{
Mod.DIRECTORY_INFO = dirInfo; // or some other appropriate value
Mod.Namespace = dirInfo.Name;

}
OUTPUT.Add(Mod);
}
OUTPUT.Add(Mod);

}
// Handle case where json is null or empty
Expand Down Expand Up @@ -350,6 +352,8 @@ public List<NORTHSTARCOMPATIBLE_MOD> READ_UPDATE_MOD_LIST(DirectoryInfo[] modsTo
if (dirInfo.Exists)
{
Mod.DIRECTORY_INFO = dirInfo; // or some other appropriate value
Mod.Namespace = dirInfo.Name;


}
Mod.Has_Valid_Mod = false;
Expand Down Expand Up @@ -387,6 +391,7 @@ public List<NORTHSTARCOMPATIBLE_MOD> READ_UPDATE_MOD_LIST(DirectoryInfo[] modsTo
if (dirInfo.Exists)
{
Mod.DIRECTORY_INFO = dirInfo; // or some other appropriate value
Mod.Namespace = dirInfo.Name;

}
OUTPUT.Add(Mod);
Expand All @@ -406,6 +411,7 @@ public List<NORTHSTARCOMPATIBLE_MOD> READ_UPDATE_MOD_LIST(DirectoryInfo[] modsTo
string dirNameWithoutVersion = match.Success ? dirName.Replace(match.Value, "") : dirName;
// Handle the case where the value is null
Mod.Name = "!" + dirNameWithoutVersion + "!";

}


Expand Down Expand Up @@ -550,7 +556,20 @@ public async Task Call_Mods_From_Folder()
}
DispatchIfNecessary(async () =>
{
Main.Current_Installed_Mods.Add(Verified_Installed_Mod.Name.Trim());
string[] parts = Verified_Installed_Mod.Namespace.Split('-');
string name = Verified_Installed_Mod.Namespace.Trim();
string author = null;
string ver = null;
if (parts.Length > 1)
{
author = parts[0];
name = parts[1];
ver = parts[2];
}
Main.Current_Installed_Mods.Add(new GENERAL_MOD { Name = name, Version = ver, Author = author });
});
}
}
Expand Down Expand Up @@ -2170,14 +2189,23 @@ void Open_Mod_Info(string FolderDir)
DispatchIfNecessary(async () =>
{
TreeViewItem treeViewItem = new TreeViewItem();
treeViewItem.Header = VTOL.Resources.Languages.Language.REQUIRES + myMObject.dependencies[x].ToString();
bool contains = Main.Current_Installed_Mods.Any(str1 =>
myMObject.dependencies[x].ToString().Replace("-", " ").Replace(".", " ")
.IndexOf(str1.Replace("-", " ").Replace(".", " "), StringComparison.OrdinalIgnoreCase) >= 0
);
treeViewItem.Header = VTOL.Resources.Languages.Language.REQUIRES + myMObject.dependencies[x].ToString();
string[] modParts = myMObject.dependencies[x].ToString().Split('-');
bool isHigherOrEqualVersion = false;
// Check if the array has at least two parts (name and version)
if (modParts.Length >= 1)
{
string modNameInMyObject = modParts[1];
string modVersionInMyObject = modParts[2];
GENERAL_MOD foundMod = Main.Current_Installed_Mods.FirstOrDefault(mod => string.Equals(mod.Name, modNameInMyObject, StringComparison.OrdinalIgnoreCase));
if(foundMod != null)
{
isHigherOrEqualVersion = Version.Parse(foundMod.Version) >= Version.Parse(modVersionInMyObject);
}
}
// Choose the relative strength of the comparison - is it almost exactly equal? or is it just close?
if (contains)
if (isHigherOrEqualVersion)
{
treeViewItem.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#1F2FC132")); // Change to your desired hex value
}
Expand Down
21 changes: 17 additions & 4 deletions VTOL_2.0.0/Pages/Page_Thunderstore.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using System.Xml.Linq;
using Threading;
using Windows.Foundation.Collections;
using static VTOL.MainWindow;
using static VTOL.Pages.Page_Mods;
using static VTOL.Pages.Page_Thunderstore;
using Path = System.IO.Path;
using Timer = System.Timers.Timer;
Expand Down Expand Up @@ -1374,7 +1376,7 @@ private static Boolean findString(String baseString, String strinfToFind, String
return false;
}

private void Compare_Mod_To_List(string modname, string Mod_version_current, HashSet<string> list, out string bg_color, out string label)
private void Compare_Mod_To_List(string modname, string Mod_version_current, HashSet<GENERAL_MOD> list, out string bg_color, out string label)
{
string res = "Install";
string bg = "#FF005D42";
Expand All @@ -1391,10 +1393,10 @@ private void Compare_Mod_To_List(string modname, string Mod_version_current, Has
foreach (var item in list)
{

if (Regex.Replace(item, @"(\d+\.)(\d+\.)(\d)", "").TrimEnd('-') == modname)
if (Regex.Replace(item.Name, @"(\d+\.)(\d+\.)(\d)", "").TrimEnd('-') == modname)
{
Regex pattern = new Regex(@"\d+(\.\d+)+");
Match m = pattern.Match(item);
Match m = pattern.Match(item.Name);
string version = m.Value;
int result = versionCompare(version, Mod_version_current);
switch (result)
Expand Down Expand Up @@ -3028,9 +3030,20 @@ async Task Call_Mods_From_Folder_Lite()

foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
string[] parts = dirInfo.Name.Split('-');
string name = dirInfo.Name;
string author = null;
string ver = null;

if (parts.Length > 1)
{
author = parts[0];
name = parts[1];
ver = parts[2];
}


Main.Current_Installed_Mods.Add(dirInfo.Name.Trim());
Main.Current_Installed_Mods.Add(new GENERAL_MOD { Name = name, Version = ver, Author= author });

}

Expand Down

0 comments on commit 2f885f9

Please sign in to comment.