From eeacb55344b3ef28d24b64c556b4c8740e247730 Mon Sep 17 00:00:00 2001 From: Malloc of Kuzkycyziklistan Date: Mon, 15 May 2017 13:19:32 -0500 Subject: [PATCH] succ dicc --- client/deploy.bat | 7 +++++ client/error.html | 35 ++++++++++++++++++--- client/lib/check.js | 17 ++++++---- client/src/Entrypoint.ts | 33 ++++++++++++++++++-- client/src/FileCache.ts | 67 +++++++++++++++++++++++++++++++++++----- client/src/Utilities.ts | 5 +++ 6 files changed, 143 insertions(+), 21 deletions(-) create mode 100644 client/deploy.bat create mode 100644 client/src/Utilities.ts diff --git a/client/deploy.bat b/client/deploy.bat new file mode 100644 index 0000000..5492ef4 --- /dev/null +++ b/client/deploy.bat @@ -0,0 +1,7 @@ +mkdir \\aroltd.com\aroltd\scape +mkdir \\aroltd.com\aroltd\scape\bin +copy /y /b index.html \\aroltd.com\aroltd\scape +copy /y /b error.html \\aroltd.com\aroltd\scape +copy /y /b style.css \\aroltd.com\aroltd\scape +copy /y /b bin\scape.js \\aroltd.com\aroltd\scape\bin +copy /y /b bin\lib.js \\aroltd.com\aroltd\scape\bin \ No newline at end of file diff --git a/client/error.html b/client/error.html index 6855bde..ece9cb2 100644 --- a/client/error.html +++ b/client/error.html @@ -24,7 +24,7 @@ font-style: italic; } - #content { + .content { width: 25%; min-width: 300px; max-width: 600px; @@ -32,6 +32,16 @@ padding: 30px 0; } + @media screen and (max-width: 480px) { + .content { + width: 75%; + } + } + + .hidden { + display: none; + } + ul { list-style: none; padding: 0; @@ -66,15 +76,22 @@ window.onload = function() { var url = window.location.href; url = url.substr(url.lastIndexOf("?") + 1); - var features = url.split("&")[0].split("=")[1]; + var params = url.split("&"); + var features = params[0].split("=")[1]; - for(var i = 1; i <= features.length; ++i) - document.getElementById("supchk"+ i).className = features[i-1] == "1" ? "mark check" : "mark cross"; + if(params.length >= 2) { + document.getElementById("noSupport").className = "content hidden"; + document.getElementById("error").className = "content"; + document.getElementById("errorText").innerText = decodeURIComponent(params[0].split("=")[1]); + } else { + for(var i = 1; i <= features.length; ++i) + document.getElementById("supchk"+ i).className = features[i-1] == "1" ? "mark check" : "mark cross"; + } } -
+

Your browser does not support the required features to run this application.

@@ -94,5 +111,13 @@ such as Mozilla Firefox or Google Chrome.

+ + \ No newline at end of file diff --git a/client/lib/check.js b/client/lib/check.js index 70b8c82..4e6b280 100644 --- a/client/lib/check.js +++ b/client/lib/check.js @@ -23,13 +23,18 @@ window.onload = function() { if(!window.indexedDB) support.idb = false; - if(!support.anim || !support.canvas || !support.webgl || !support.idb) { - window.location.href = "error.html?err="+ (+support.anim) - +""+ (+support.canvas) - +""+ (+support.webgl) - +""+ (+support.idb); + var supported = true; + for(var i in support) + supported = supported && support[i]; + + if(!supported) { + var supportStr = ""; + for(var i in support) + supportStr += ""+ (+support[i]); + + window.location.href = "error.html?err="+ supportStr; return; } - Entrypoint.Main(); + Entrypoint.Start(); } diff --git a/client/src/Entrypoint.ts b/client/src/Entrypoint.ts index 3c075f6..3a30cbd 100644 --- a/client/src/Entrypoint.ts +++ b/client/src/Entrypoint.ts @@ -1,7 +1,36 @@ /// +/// class Entrypoint { - static Main(): void { - FileCache.Initialize(); + private static InitStatus = { + FileCache: false + } + + private static InitCheck(): void { + var done = true; + for(var i in Entrypoint.InitStatus) + done = done && Entrypoint.InitStatus[i]; + + if(done) + Entrypoint.Initialized(); + } + + public static Start(): void { + FileCache.Initialize( + // SUCCESS + () => { + Entrypoint.InitStatus.FileCache = true; + this.InitCheck(); + }, + + // FAILURE + (error: string) => { + CriticalStop.Redirect(error); + } + ); + } + + private static Initialized(): void { + } } \ No newline at end of file diff --git a/client/src/FileCache.ts b/client/src/FileCache.ts index f48d697..f40a383 100644 --- a/client/src/FileCache.ts +++ b/client/src/FileCache.ts @@ -1,17 +1,68 @@ class FileCache { - static dbHandle: IDBDatabase = null; + private static DB: IDBDatabase = null; - static Initialize(): void { - var request = window.indexedDB.open("fileCache", 1); + public static Initialize(success: ()=>void, error: (error: string)=>void): void { + var request = window.indexedDB.open("fileCache", 2); - request.onupgradeneeded = function(event: any) { + request.onupgradeneeded = (event: any) => { var db: IDBDatabase = event.target.result; - db.createObjectStore("files", {keyPath: "name"}); + if(db.objectStoreNames.contains("hashes")) + db.deleteObjectStore("hashes"); + + if(!db.objectStoreNames.contains("files")) + db.createObjectStore("files", {keyPath: "Name", autoIncrement: false}); + + if(!db.objectStoreNames.contains("metadata")) + db.createObjectStore("metadata", {keyPath: "Name", autoIncrement: false}); }; - request.onsuccess = function(event: any) { - - } + request.onerror = (event: any) => { + error("Could not upgrade the client database to the most recent version."); + }; + + request.onsuccess = (event: any) => { + FileCache.DB = request.result; + success(); + }; } + public static GetHash(fileName: string, success: (hash: string)=>void, error: (error: string)=>void): void { + var query = FileCache.DB.transaction("metadata"); + var store = query.objectStore("metadata"); + var request = store.get(fileName); + + request.onsuccess = () => { + success(request.result); + }; + + request.onerror = (event: any) => { + error(event); + }; + } + + public static SetHash(fileName: string, hash: string) { + var query = FileCache.DB.transaction("metadata", "readwrite"); + var store = query.objectStore("metadata"); + store.put({Name: fileName, Hash: hash}); + } + + public static GetFile(fileName: string, success: (data: Uint8Array)=>void, error: (error: string)=>void): void { + var query = FileCache.DB.transaction("files"); + var store = query.objectStore("files"); + var request = store.get(fileName); + + request.onsuccess = () => { + success(request.result); + }; + + request.onerror = (event: any) => { + error(event); + }; + } + + public static SetFile(fileName: string, data: Uint8Array) { + var query = FileCache.DB.transaction("files", "readwrite"); + var store = query.objectStore("files"); + store.put(data, fileName); + } } \ No newline at end of file diff --git a/client/src/Utilities.ts b/client/src/Utilities.ts new file mode 100644 index 0000000..2c260cc --- /dev/null +++ b/client/src/Utilities.ts @@ -0,0 +1,5 @@ +class CriticalStop { + public static Redirect(message: string): void { + window.location.href = "error.html?txt="+ encodeURIComponent(message) +"&rterr"; + } +} \ No newline at end of file