forgot to recompile lib.js
do that at home
This commit is contained in:
parent
2524d88561
commit
6ca8bade21
6 changed files with 81 additions and 57 deletions
|
@ -36,5 +36,5 @@ window.onload = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entrypoint.Start();
|
Entrypoint.start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,35 +2,35 @@
|
||||||
/// <reference path="Utilities.ts" />
|
/// <reference path="Utilities.ts" />
|
||||||
|
|
||||||
class Entrypoint {
|
class Entrypoint {
|
||||||
private static InitStatus = {
|
private static initStatus = {
|
||||||
FileCache: false
|
fileCache: false
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InitCheck(): void {
|
private static initCheck(): void {
|
||||||
var done = true;
|
var done = true;
|
||||||
for(var i in Entrypoint.InitStatus)
|
for(var i in Entrypoint.initStatus)
|
||||||
done = done && Entrypoint.InitStatus[i];
|
done = done && Entrypoint.initStatus[i];
|
||||||
|
|
||||||
if(done)
|
if(done)
|
||||||
Entrypoint.Initialized();
|
Entrypoint.ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Start(): void {
|
public static start(): void {
|
||||||
FileCache.Initialize(
|
FileCache.initCache(
|
||||||
// SUCCESS
|
// SUCCESS
|
||||||
() => {
|
() => {
|
||||||
Entrypoint.InitStatus.FileCache = true;
|
Entrypoint.initStatus.fileCache = true;
|
||||||
this.InitCheck();
|
this.initCheck();
|
||||||
},
|
},
|
||||||
|
|
||||||
// FAILURE
|
// FAILURE
|
||||||
(error: string) => {
|
(error: string) => {
|
||||||
CriticalStop.Redirect(error);
|
CriticalStop.redirect(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Initialized(): void {
|
private static ready(): void {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,19 +3,19 @@
|
||||||
// ** STRING EXTENSIONS ** \\
|
// ** STRING EXTENSIONS ** \\
|
||||||
|
|
||||||
interface String {
|
interface String {
|
||||||
ReplaceAll(needle: string[], replace: string, ignoreCase?: boolean): string;
|
replaceAll(needle: string[], replace: string, ignoreCase?: boolean): string;
|
||||||
ReplaceAll(needle: string[], replace: string[], ignoreCase?: boolean): string;
|
replaceAll(needle: string[], replace: string[], ignoreCase?: boolean): string;
|
||||||
ReplaceAll(needle: string, replace: string, ignoreCase?: boolean): string;
|
replaceAll(needle: string, replace: string, ignoreCase?: boolean): string;
|
||||||
Contains(needle: string, ignoreCase?: boolean): boolean;
|
contains(needle: string, ignoreCase?: boolean): boolean;
|
||||||
|
|
||||||
StripCharacters(chars: string): string;
|
stripCharacters(chars: string): string;
|
||||||
|
|
||||||
HasUnicodeCharacters(): boolean;
|
hasUnicodeCharacters(): boolean;
|
||||||
ToByteArray(): Uint8Array;
|
toByteArray(): Uint8Array;
|
||||||
ByteLength(): number;
|
byteLength(): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
String.prototype.ReplaceAll = function(needle: any, replace: any, ignoreCase: boolean = false): string {
|
String.prototype.replaceAll = function(needle: any, replace: any, ignoreCase: boolean = false): string {
|
||||||
if((typeof needle) == "string")
|
if((typeof needle) == "string")
|
||||||
return this.replace(new RegExp(needle.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignoreCase?"gi":"g")),(typeof(replace)=="string")?replace.replace(/\$/g,"$$$$"):replace);
|
return this.replace(new RegExp(needle.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignoreCase?"gi":"g")),(typeof(replace)=="string")?replace.replace(/\$/g,"$$$$"):replace);
|
||||||
else {
|
else {
|
||||||
|
@ -30,13 +30,13 @@ String.prototype.ReplaceAll = function(needle: any, replace: any, ignoreCase: bo
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.Contains = function(needle: string, ignoreCase: boolean = false): boolean {
|
String.prototype.contains = function(needle: string, ignoreCase: boolean = false): boolean {
|
||||||
return ignoreCase
|
return ignoreCase
|
||||||
? this.toLowerCase().indexOf(needle.toLowerCase()) != -1
|
? this.toLowerCase().indexOf(needle.toLowerCase()) != -1
|
||||||
: this.indexOf(needle) != -1;
|
: this.indexOf(needle) != -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.StripCharacters = function(chars: string) {
|
String.prototype.stripCharacters = function(chars: string) {
|
||||||
var copy = this;
|
var copy = this;
|
||||||
if(chars != "")
|
if(chars != "")
|
||||||
copy = copy.replaceAll(chars.split(""), "");
|
copy = copy.replaceAll(chars.split(""), "");
|
||||||
|
@ -44,18 +44,18 @@ String.prototype.StripCharacters = function(chars: string) {
|
||||||
return copy;
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.HasUnicodeCharacters = function() {
|
String.prototype.hasUnicodeCharacters = function() {
|
||||||
for(var i = 0; i < this.length; i++) {
|
for(var i = 0; i < this.length; i++) {
|
||||||
if(this.charCodeAt(i) > 127) return true;
|
if(this.charCodeAt(i) > 127) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.ByteLength = function() {
|
String.prototype.byteLength = function() {
|
||||||
return utf8.encode(this).length;
|
return utf8.encode(this).length;
|
||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.ToByteArray = function() {
|
String.prototype.toByteArray = function() {
|
||||||
var str = utf8.encode(this);
|
var str = utf8.encode(this);
|
||||||
var ret = new Uint8Array(str.length);
|
var ret = new Uint8Array(str.length);
|
||||||
for(var i = 0; i < str.length; i++)
|
for(var i = 0; i < str.length; i++)
|
||||||
|
@ -73,7 +73,8 @@ interface DateConstructor {
|
||||||
|
|
||||||
interface Date {
|
interface Date {
|
||||||
toUnixTime(): number;
|
toUnixTime(): number;
|
||||||
toDateTimeString(): string;
|
/*ToDateTimeString(): string;
|
||||||
|
ToTimeString(): string;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Date.unixNow = function() {
|
Date.unixNow = function() {
|
||||||
|
@ -84,13 +85,13 @@ Date.prototype.toUnixTime = function() {
|
||||||
return Math.floor(this.getTime()/1000);
|
return Math.floor(this.getTime()/1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
Date.prototype.toDateTimeString = function() {
|
/*Date.prototype.ToDateTimeString = function() {
|
||||||
return this.toDateString() +" @ "+ this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad();
|
return this.toDateString() +" @ "+ this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad();
|
||||||
};
|
};
|
||||||
|
|
||||||
Date.prototype.toTimeString = function() {
|
Date.prototype.ToTimeString = function() {
|
||||||
return this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad();
|
return this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad();
|
||||||
};
|
};*/
|
||||||
|
|
||||||
|
|
||||||
// ** NUMBER EXTENSIONS ** \\
|
// ** NUMBER EXTENSIONS ** \\
|
||||||
|
@ -119,18 +120,17 @@ Number.prototype.packBytes = function(bytes: number) {
|
||||||
|
|
||||||
interface Uint8Array {
|
interface Uint8Array {
|
||||||
unpackBytes(): number;
|
unpackBytes(): number;
|
||||||
toString(): string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8Array.prototype.unpackBytes = function() {
|
Uint8Array.prototype.unpackBytes = function(): number {
|
||||||
var ret = 0;
|
var ret = 0;
|
||||||
for(var i = 0; i < this.length; i++)
|
for(var i = 0; i < this.length; i++)
|
||||||
ret = ret | ((this[i] & 0xFF) << 8*(this.length - 1 - i));
|
ret = ret | ((this[i] & 0xFF) << 8*(this.length - 1 - i));
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
Uint8Array.prototype.toString = function() {
|
Uint8Array.prototype.toString = function(): string {
|
||||||
var chunkSize = 10000;
|
var chunkSize = 4096;
|
||||||
var raw = "";
|
var raw = "";
|
||||||
for(var i = 0;; i++) {
|
for(var i = 0;; i++) {
|
||||||
if(this.length < chunkSize*i) break;
|
if(this.length < chunkSize*i) break;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class FileCache {
|
class FileCache {
|
||||||
private static DB: IDBDatabase = null;
|
private static dbHandle: IDBDatabase = null;
|
||||||
|
|
||||||
public static Initialize(success: ()=>void, error: (error: string)=>void): void {
|
public static initCache(success: ()=>void, error: (error: string)=>void): void {
|
||||||
var request = window.indexedDB.open("fileCache", 2);
|
var request = window.indexedDB.open("fileCache", 2);
|
||||||
|
|
||||||
request.onupgradeneeded = (event: any) => {
|
request.onupgradeneeded = (event: any) => {
|
||||||
|
@ -21,13 +21,13 @@ class FileCache {
|
||||||
};
|
};
|
||||||
|
|
||||||
request.onsuccess = (event: any) => {
|
request.onsuccess = (event: any) => {
|
||||||
FileCache.DB = request.result;
|
FileCache.dbHandle = request.result;
|
||||||
success();
|
success();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GetMeta(fileName: string, success: (meta: FileMeta)=>void, error: (error: string)=>void): void {
|
public static getMeta(fileName: string, success: (meta: FileMeta)=>void, error: (error: string)=>void): void {
|
||||||
var query = FileCache.DB.transaction("metadata");
|
var query = FileCache.dbHandle.transaction("metadata");
|
||||||
var store = query.objectStore("metadata");
|
var store = query.objectStore("metadata");
|
||||||
var request = store.get(fileName);
|
var request = store.get(fileName);
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ class FileCache {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SetMeta(meta: FileMeta) {
|
public static setMeta(meta: FileMeta) {
|
||||||
var query = FileCache.DB.transaction("metadata", "readwrite");
|
var query = FileCache.dbHandle.transaction("metadata", "readwrite");
|
||||||
var store = query.objectStore("metadata");
|
var store = query.objectStore("metadata");
|
||||||
store.put(meta);
|
store.put(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GetFile(fileName: string, success: (data: Uint8Array)=>void, error: (error: string)=>void): void {
|
public static getFile(fileName: string, success: (data: Uint8Array)=>void, error: (error: string)=>void): void {
|
||||||
var query = FileCache.DB.transaction("files");
|
var query = FileCache.dbHandle.transaction("files");
|
||||||
var store = query.objectStore("files");
|
var store = query.objectStore("files");
|
||||||
var request = store.get(fileName);
|
var request = store.get(fileName);
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ class FileCache {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SetFile(fileName: string, data: Uint8Array) {
|
public static setFile(fileName: string, data: Uint8Array) {
|
||||||
var query = FileCache.DB.transaction("files", "readwrite");
|
var query = FileCache.dbHandle.transaction("files", "readwrite");
|
||||||
var store = query.objectStore("files");
|
var store = query.objectStore("files");
|
||||||
store.put(data, fileName);
|
store.put(data, fileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,43 @@ const enum kPacketId {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Packet {
|
class Packet {
|
||||||
private _Id: kPacketId;
|
private _id: kPacketId;
|
||||||
public get Id(): kPacketId {
|
public get id(): kPacketId {
|
||||||
return this._Id;
|
return this._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _IsLegal: boolean = true;
|
private _isLegal: boolean = true;
|
||||||
public get IsLegal(): boolean {
|
public get isLegal(): boolean {
|
||||||
return this._IsLegal;
|
return this._isLegal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Regions: Uint8Array[] = [];
|
private _regions: Uint8Array[] = [];
|
||||||
|
public get regions(): Uint8Array[] {
|
||||||
|
return this._regions;
|
||||||
|
}
|
||||||
|
public get regionCount(): number {
|
||||||
|
return this._regions.length;
|
||||||
|
}
|
||||||
|
public getRegion(region: number): Uint8Array {
|
||||||
|
return this._regions[region];
|
||||||
|
}
|
||||||
|
public getRegionString(region: number): string {
|
||||||
|
return this.getRegion(region).toString();
|
||||||
|
}
|
||||||
|
|
||||||
public get RegionCount(): number {
|
public getBytes(): Uint8Array {
|
||||||
return this.Regions.length;
|
var messageSize = 1;
|
||||||
|
this._regions.forEach(region => {
|
||||||
|
messageSize += region.byteLength + 1;
|
||||||
|
if(region.byteLength >= 254 && region.byteLength <= 0xFFFF)
|
||||||
|
messageSize += 2;
|
||||||
|
else
|
||||||
|
messageSize += 4;
|
||||||
|
});
|
||||||
|
|
||||||
|
var buffer = new Uint8Array(messageSize);
|
||||||
|
this._regions.forEach(region => {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
class CriticalStop {
|
class CriticalStop {
|
||||||
public static Redirect(message: string): void {
|
public static redirect(message: string): void {
|
||||||
window.location.href = "error.html?txt="+ encodeURIComponent(message) +"&rterr";
|
window.location.href = "error.html?txt="+ encodeURIComponent(message) +"&rterr";
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue