Skip to content

Commit

Permalink
Added the start of self checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Jun 6, 2020
1 parent 4e54623 commit 8437086
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RsMapper/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Form1()
// Read components json and retrieve redstone components.
public void GetComps()
{
using (StreamReader r = new StreamReader("Components.json"))
using (StreamReader r = new StreamReader(PrgmSelfCheck.ComponentsJson))
{
string json = r.ReadToEnd();
Console.Write(json);
Expand Down
52 changes: 52 additions & 0 deletions RsMapper/PrgmSelfCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Windows.Forms;

namespace RsMapper
{
public class PrgmSelfCheck
{
// DEPENDANCIES
public static string ComponentsJson = "Components.json";
public static string JsonNet = "Newtonsoft.Json.dll";
public static string JsonNetXml = "Newtonsoft.Json.xml";

WebClient wc = new WebClient();

/// <summary>
/// Check for any missing files that are required to start the program.
/// </summary>
public void CheckAll()
{
if(File.Exists(ComponentsJson) == false)
{

// Check for components settings file.
if(MessageBox.Show("The file " + ComponentsJson + " is missing. Would you like to redownload it?", "Missing Dependancy", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
{

// Reinstall the file if the user clicks yes.
wc.DownloadFile("https://raw.githubusercontent.com/GreenJamesDev/RsMapper/master/RsMapper/Components.json", AppDomain.CurrentDomain.BaseDirectory + "Components.json");


} else
{

// If the user chooses not to reinstall the file, exit RsMapper.
Application.Exit();
}

}



}


}
}
5 changes: 5 additions & 0 deletions RsMapper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ static class Program
[STAThread]
static void Main()
{

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

PrgmSelfCheck sc = new PrgmSelfCheck();
sc.CheckAll();

Application.Run(new Form1());
}
}
Expand Down
1 change: 1 addition & 0 deletions RsMapper/RsMapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>imgs.resx</DependentUpon>
</Compile>
<Compile Include="PrgmSelfCheck.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RsComponent.cs" />
Expand Down

0 comments on commit 8437086

Please sign in to comment.