Skip to content

Commit

Permalink
[Constants] add new parameter - programs_list (contains applications …
Browse files Browse the repository at this point in the history
…list data)

[Functions] implemented new flag(s) --list-applications (get available applications to install)
[Functions] Implemented new functions isWindowsXP (checks if the current Windows version is Windows XP) and IsDotNet45orNewer
  • Loading branch information
nixxoq committed May 16, 2024
1 parent 9f7201e commit 4dc4b16
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 36 deletions.
30 changes: 17 additions & 13 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ class Program
{
static void Main(string[] args)
{
// Iniyializing Security Protocols for HTTPS requests
// Checks if current operating system is Windows XP (NT 5.1 & NT 5.2)
// However, I am thinking about adding support for Windows Vista when the One-Core-API 4.1.0 will be released 👀
if (!Functions.isWindowsXP())
{
Console.WriteLine("This program works only on Windows XP.");
return;
}

// Checks if .NET Framework 4.5 or newer is installed
// It's need for TLS 1.2 protocol
if (!Functions.IsDotNet45orNewer())
{
Console.WriteLine("This program works only with installed .NET Framework 4.0 and 4.5+\nMake sure you have installed the One-Core-API before installing .NET Framework 4.5+!");
return;
}

// Initializing Security Protocols for HTTPS requests
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

Functions.parseArgs(args);

//try
//{
// //string content = Functions.getContent("https://raw.githubusercontent.com/snaky1a/xp-apps/development/upd.json");
// //Functions.parseJson(content);
// //Console.ReadLine();
//}
//catch (Exception ex)
//{
// Console.WriteLine("An error occurred: " + ex.Message);
// Console.ReadLine();
//}
}

}
Expand Down
13 changes: 2 additions & 11 deletions sources/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@

namespace xp_apps.sources.constants
namespace xp_apps.sources.constants
{
public static class Constants
{
public static string PROGRAM_VERSION = "0.1.0";
//public Constants()
//{
// public static string PROGRAM_VERSION = "0.1.0";
//}
public static object programs_list = Functions.getUpdates();
}
}


//public class ApplicationResponse
//{
// [JsonProperty("test")]
//}
93 changes: 81 additions & 12 deletions sources/Functions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net;
using Microsoft.Win32;
using Newtonsoft.Json;
using xp_apps.sources.constants;

Expand All @@ -11,7 +12,7 @@ class Functions
$"\n\nList of available arguments:\n\n[Option]\t\t\t\t[Description]" +
$"\n-h, --help\t\t\t\tDisplay this help message" +
$"\n-i, --install\t\t\t\tInstall Application from XP-Apps repository" +
$"\n-l, --list, --list-applications\t\tList all available applications in the repository" +
$"\n-l, --list, --list-applications,\tList all available applications in the repository \n--list-apps or --apps" +
$"\n\nExample:\n xp-apps.exe -i PyCharm2023 or xp-apps.exe --install PyCharm2023";

/// <summary>
Expand All @@ -25,12 +26,17 @@ public static void parseArgs(string[] args)
if (arg.Equals("-i") || arg.Equals("--install"))
{
Console.WriteLine("Unimplemented.");
break;
return;
}
else if (arg.Equals("-h") || arg.Equals("--help"))
{
Console.WriteLine(HELP);
break;
return;
}
else if (arg.Equals("-l") || arg.Equals("--list") || arg.Equals("--list-applications") || arg.Equals("--list-apps") || arg.Equals("--apps"))
{
getApplications(Constants.programs_list);
return;
}
}
Console.WriteLine(HELP);
Expand All @@ -49,14 +55,23 @@ public static string getContent(string url)
}
}

public static object getUpdates()
{
// hardcode... yeah
// TODO: add UPDATE_JSON variable to Constants.cs
return parseJson(getContent("https://raw.githubusercontent.com/Snaky1a/xp-apps/development/upd.json"));
}

/// <summary>
/// Parse string to dynamic object
/// </summary>
/// <param name="content">String to parse</param>
public static void parseJson(string content)
public static object parseJson(string content)
{
dynamic Jobj = JsonConvert.DeserializeObject(content);
getApplications(Jobj);
object Jobj = JsonConvert.DeserializeObject(content);
//getApplications(Jobj);
//return Jobj.ToString();
return Jobj;
}

/// <summary>
Expand All @@ -65,16 +80,70 @@ public static void parseJson(string content)
/// <param name="json">Applications list (json object)</param>
static void getApplications(dynamic json)
{
int count = 1;
foreach (var category in json)
Console.WriteLine($"List of available applications:\nFormat:\n[Category] [Application Name]");
foreach (dynamic category in json)
{
string categoryName = category.Name;
foreach (var app in category.Value)
{
Console.WriteLine($"{count}. [{categoryName}] - [{app.Value["filename"]}]");
count++;
}
Console.WriteLine($"{categoryName}\t\t{app.Value["filename"]}");
}
}

/// <summary>
/// Checks if the current Windows version is Windows XP
/// </summary>
public static bool isWindowsXP()
{
OperatingSystem os = Environment.OSVersion;
Version osv = os.Version;

if (os.Platform == PlatformID.Win32NT)
{
if (osv.Major == 5 && osv.Minor == 1)
return true;
if (osv.Major == 5 && osv.Minor == 5)
return true;
}
return false;
}



// https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#query-the-registry-using-code
public static bool IsDotNet45orNewer()
{
var localkey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\");

if (localkey != null && localkey.GetValue("Release") != null)
if ((int)localkey.GetValue("Release") >= 378389)
return false;

return true;

//if (releaseKey >= 533320)
// return "4.8.1 or later";
//if (releaseKey >= 528040)
// return "4.8";
//if (releaseKey >= 461808)
// return "4.7.2";
//if (releaseKey >= 461308)
// return "4.7.1";
//if (releaseKey >= 460798)
// return "4.7";
//if (releaseKey >= 394802)
// return "4.6.2";
//if (releaseKey >= 394254)
// return "4.6.1";
//if (releaseKey >= 393295)
// return "4.6";
//if (releaseKey >= 379893)
// return "4.5.2";
//if (releaseKey >= 378675)
// return "4.5.1";
//if (releaseKey >= 378389)
// return "4.5";

//return "No 4.5 or later version detected";
}
}
}

0 comments on commit 4dc4b16

Please sign in to comment.