add app icon, add settings saving, improve version detection

This commit is contained in:
Persephone Bubblegum-Holiday 2025-02-11 15:24:00 -07:00
parent e46a50b8f1
commit 66d458df47
10 changed files with 310 additions and 33 deletions

View file

@ -1,4 +1,6 @@
using System;
using networkPaint.Properties;
using System;
using System.Collections.Specialized;
using System.Drawing;
using System.Net;
@ -8,21 +10,24 @@ namespace networkPaint
{
public partial class MainForm : Form
{
Random r = new Random();
WebClient client = new WebClient();
Bitmap bitmap = new Bitmap(640, 480);
Graphics graphics;
Color color;
Color color = Color.Black;
string url = "http://kawaiizenbo.me/toys/networkpaint/";
string versionString = "networkPaint/1.2";
bool dragging = false;
public MainForm()
{
InitializeComponent();
color = intToRGB(r.Next(0, 0xFFFFFF));
paintArea.Image = bitmap;
graphics = Graphics.FromImage(bitmap);
client.Headers.Add("User-Agent", versionString);
brushSizeNumericUpDown.Value = Settings.Default.size;
color = intToRGB(Settings.Default.color);
url = Settings.Default.url;
}
private void paintArea_MouseUp(object sender, MouseEventArgs e)
@ -50,13 +55,24 @@ namespace networkPaint
private void MainForm_Load(object sender, EventArgs e)
{
if (client.DownloadString(urlTextBox.Text + "/valid.txt").Trim() == "networkPaint") timer.Start();
string validString;
try
{
validString = client.DownloadString(urlTextBox.Text + "/valid.txt").Trim();
}
catch (Exception)
{
MessageBox.Show("This is not a valid networkPaint endpoint.");
urlTextBox.Text = url;
return;
}
if (validString == versionString) timer.Start();
else MessageBox.Show($"Version mismatch! Server is designed for {validString} and you are running {versionString}");
}
private void timer_Tick(object sender, EventArgs e)
{
string responseString = client.DownloadString(url + "data.ppf");
client.Dispose();
if (responseString.Trim() == "") return;
graphics.Clear(Color.White);
foreach (string packet in responseString.Split(';'))
@ -82,13 +98,16 @@ namespace networkPaint
{
colorDialog.ShowDialog();
color = colorDialog.Color;
Settings.Default.color = rgbToInt(color);
Settings.Default.Save();
}
private void setUrlButton_Click(object sender, EventArgs e)
{
string validString;
try
{
if (client.DownloadString(urlTextBox.Text + "/valid.txt").Trim() != "networkPaint") throw new Exception();
validString = client.DownloadString(urlTextBox.Text + "/valid.txt").Trim();
}
catch (Exception)
{
@ -96,12 +115,27 @@ namespace networkPaint
urlTextBox.Text = url;
return;
}
if (validString != versionString)
{
MessageBox.Show($"Version mismatch! Server is designed for {validString} and you are running {versionString}");
urlTextBox.Text = url;
return;
}
string tempURL = urlTextBox.Text;
if (!tempURL.EndsWith("")) tempURL += "/";
url = tempURL;
Settings.Default.url = url;
Settings.Default.Save();
bitmap = new Bitmap(640, 480);
paintArea.Image = bitmap;
graphics = Graphics.FromImage(bitmap);
timer.Start();
}
private void brushSizeNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Settings.Default.size = (int)brushSizeNumericUpDown.Value;
Settings.Default.Save();
}
public static int rgbToInt(Color color)