Skip to content

Commit

Permalink
bug fixes, auto updater, option to disable directory listing
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanaobrien committed Aug 11, 2022
1 parent 6c1dd56 commit d7ca5aa
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 36 deletions.
88 changes: 75 additions & 13 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 32 additions & 4 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace WebServer
{
public partial class WebServer : Form
{
private double version = 2.4;
Server mainServer;
private string pathToServe;
private int port = 8080;
Expand All @@ -16,6 +17,15 @@ public WebServer()
{
InitializeComponent();
loadSettings();
this.BottomLeftLabel.Text = "C Server Version " + this.version;
Updater update = new Updater(this.version);
update.check4Updates((double version) =>
{
this.UpdateLink.Visible = true;
this.UpdateTitle.Visible = true;
this.UpdateVersion.Visible = true;
this.UpdateVersion.Text = "Version " + version + " is out!";
});
}
private void toggleServer()
{
Expand All @@ -36,7 +46,7 @@ private void startServer()
{
this.MSG.Visible = false;
this.URL.Visible = true;
mainServer = new Server(pathToServe, port, PUT.Checked, DELETE.Checked, CORS.Checked, AutoIndex.Checked);
mainServer = new Server(pathToServe, port, PUT.Checked, DELETE.Checked, CORS.Checked, AutoIndex.Checked, ListDirectory.Checked);
this.localHostURL = "http://localhost:" + port + "/";
this.URL.Text = "Open " + this.localHostURL + " in your browser";
}
Expand All @@ -46,16 +56,16 @@ private void saveSettings()
{
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "C-server", "config.1");
string folder = Path.GetDirectoryName(path);
if (!Directory.Exists(folder))
if (!System.IO.Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
System.IO.Directory.CreateDirectory(folder);
}
if (File.Exists(path))
{
File.Delete(path);
}
FileStream fs = File.Create(path);
byte[] data = Encoding.UTF8.GetBytes(port + "\n" + pathToServe + "\n" + (PUT.Checked ? "1" : "0") + "\n" + (DELETE.Checked ? "1" : "0") + "\n" + (CORS.Checked ? "1" : "0") + "\n" + (AutoIndex.Checked ? "1" : "0") + "\n");
byte[] data = Encoding.UTF8.GetBytes(port + "\n" + pathToServe + "\n" + (PUT.Checked ? "1" : "0") + "\n" + (DELETE.Checked ? "1" : "0") + "\n" + (CORS.Checked ? "1" : "0") + "\n" + (AutoIndex.Checked ? "1" : "0") + "\n" + (ListDirectory.Checked ? "1" : "0") + "\n");
fs.Write(data, 0, data.Length);
fs.Close();
}
Expand Down Expand Up @@ -104,6 +114,10 @@ private void loadSettings()
{
AutoIndex.Checked = (cl.Equals("1"));
}
else if (i == 6)
{
ListDirectory.Checked = (cl.Equals("1"));
}
i++;
}
this.ServingPath.Text = "Currently Serving: " + pathToServe;
Expand Down Expand Up @@ -200,6 +214,15 @@ private void AutoIndex_CheckStateChanged(object sender, EventArgs e)
saveSettings();
}

private void ListDirectory_CheckStateChanged(object sender, EventArgs e)
{
if (mainServer != null)
{
mainServer.setDirectory(ListDirectory.Checked);
}
saveSettings();
}

private void viewOnGithub_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/ethanaobrien/C-server");
Expand All @@ -209,6 +232,11 @@ private void URL_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(this.localHostURL);
}

private void UpdateLink_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/ethanaobrien/C-server/releases/latest");
}
}
}

Expand Down
Loading

0 comments on commit d7ca5aa

Please sign in to comment.