Twitch Desktop Notification
Twitch has been success fully connected. Please close this tab.
State does not match up preventing XSS.
")); + response.OutputStream.Close(); + } + } + + private void RespondFavicon(HttpListenerResponse response) + { + response.StatusCode = (int)HttpStatusCode.OK; + response.ContentType = "image/x-icon"; + response.OutputStream.Write(File.ReadAllBytes("Assets/icon.ico")); + response.OutputStream.Close(); + } + + private void processRequestThread(object? obj) + { + HttpListenerContext context = (HttpListenerContext)obj; + HttpListenerRequest request = context.Request; + + if (request.Url.AbsolutePath == "/favicon.ico") + { + RespondFavicon(context.Response); + } + else if (request.Url.AbsolutePath == "/twitchRedirect") + { + RespondConnection(request, context.Response); + } + else + { + HttpListenerResponse response = context.Response; + response.StatusCode = (int)HttpStatusCode.NotFound; + response.ContentType = "text/html"; + response.OutputStream.Write(Encoding.ASCII.GetBytes("File not found
")); + response.OutputStream.Close(); + } + } + + private void ThreadManagedServer() + { + while (listener.IsListening) + { + try + { + HttpListenerContext context = listener.GetContext(); + ParameterizedThreadStart pts = new ParameterizedThreadStart(processRequestThread); + pts.Invoke(context); + } + catch (Exception e) + { + } + } + } + } +} diff --git a/TwitchDesktopNotifications/DataStore.cs b/TwitchDesktopNotifications/DataStore.cs new file mode 100644 index 0000000..79c98f1 --- /dev/null +++ b/TwitchDesktopNotifications/DataStore.cs @@ -0,0 +1,65 @@ +using System.Text.Json; +using TwitchDesktopNotifications.JsonStructure; +using System.IO; + +namespace TwitchDesktopNotifications +{ + internal class DataStore + { + private DataStore() { } + + public static DataStore Instance { get; private set; } + private Store _store; + public JsonStructure.Store Store { + get { + if (_store == null) + { + Load(); + } + return _store; + } + private set { + _store = value; + } + } + + public bool isLoaded { get; private set; } + + public static DataStore GetInstance() + { + if(Instance == null) + { + Instance = new DataStore(); + } + return Instance; + } + + public void Save() + { + String FilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TwitchNotify"); + String FileName = "store.json"; + + string fileContent = JsonSerializer.Serialize