Skip to content

Commit

Permalink
[Functions]: Implemented parseArgs function
Browse files Browse the repository at this point in the history
  • Loading branch information
nixxoq committed May 15, 2024
1 parent 43bda82 commit 9f7201e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 29 deletions.
26 changes: 14 additions & 12 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ class Program
{
static void Main(string[] args)
{

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

try
{
string content = Functions.getFile("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();
}
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
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
## xp-apps

<!-- A repository with applications that work with One-Core-API -->
### The package manager for Windows XP with modern applications that work with One-Core-API
### Package manager for Windows XP with modern applications that work with One-Core-API

19 changes: 10 additions & 9 deletions sources/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace xp_apps.sources

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


//public class ApplicationResponse
//{
// [JsonProperty("test")]
//}
}
57 changes: 50 additions & 7 deletions sources/Functions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,68 @@
using System;
using System.Net;
using Newtonsoft.Json;
using xp_apps.sources.constants;

namespace xp_apps.sources
{
class Functions
{
public static string getFile(string url)
private static string HELP = $"XP-Apps ver {Constants.PROGRAM_VERSION}" +
$"\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\nExample:\n xp-apps.exe -i PyCharm2023 or xp-apps.exe --install PyCharm2023";

/// <summary>
/// Parse arguments from command line
/// </summary>
/// <param name="args">arguments from main function</param>
public static void parseArgs(string[] args)
{
foreach (string arg in args)
{
if (arg.Equals("-i") || arg.Equals("--install"))
{
Console.WriteLine("Unimplemented.");
break;
}
else if (arg.Equals("-h") || arg.Equals("--help"))
{
Console.WriteLine(HELP);
break;
}
}
Console.WriteLine(HELP);
}

/// <summary>
/// Get content from URL
/// </summary>
/// <param name="url">URL link</param>
/// <returns>URL content</returns>
public static string getContent(string url)
{
using (WebClient client = new WebClient())
{
return client.DownloadString(url);
}
}

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

/// <summary>
/// Get all applications available to install
/// </summary>
/// <param name="json">Applications list (json object)</param>
static void getApplications(dynamic json)
{
int count = 1;
Expand All @@ -27,11 +76,5 @@ static void getApplications(dynamic json)
}
}
}

public static void parseJson(string content)
{
dynamic Jobj = JsonConvert.DeserializeObject(content);
getApplications(Jobj);
}
}
}

0 comments on commit 9f7201e

Please sign in to comment.