Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Checkpoint work on creating a virtual filesystem out of File and Asse…

…t entries loaded by the preloader

VirtualVolume/VirtualDirectory.enumerate return nodes instead of names
  • Loading branch information...
commit 01c2d5fe15003b4af792334e2fc324b8dad0c74f 1 parent 5d349fe
@kg kg authored
View
15 Libraries/JSIL.Browser.js
@@ -182,6 +182,7 @@ if (statsElement !== null) {
var allFiles = {};
var allAssets = {};
+var storageRoot = null;
var heldKeys = [];
var heldButtons = [];
var mousePosition = [0, 0];
@@ -776,11 +777,25 @@ function finishLoading () {
var started = Date.now();
var endBy = started + finishStepDuration;
+ var initFileStorage = function (volume) {
+ for (var k in allFiles) {
+ if (!allFiles.hasOwnProperty(k))
+ continue;
+
+ var file = volume.createFile(k, false, true);
+ file.writeAllBytes(allFiles[k]);
+ }
+ };
+
var initIfNeeded = function () {
if (!state.jsilInitialized) {
state.jsilInitialized = true;
JSIL.Initialize();
}
+
+ if (typeof ($jsilreadonlystorage) !== "undefined") {
+ storageRoot = new ReadOnlyStorageVolume("files", "files:/", initFileStorage);
+ }
};
while (Date.now() <= endBy) {
View
4 Libraries/JSIL.LocalStorage.js
@@ -41,7 +41,7 @@ JSIL.MakeClass($jsilstorage.TypeRef("VirtualVolume"), "LocalStorageVolume", true
this.writeInodes(this.name);
});
- $.RawMethod(false, "getBlob", function (name) {
+ $.RawMethod(false, "getFileBytes", function (name) {
var key = getKey(this.name) + "_blobs_" + name;
var json = localStorage.getItem(key);
@@ -55,7 +55,7 @@ JSIL.MakeClass($jsilstorage.TypeRef("VirtualVolume"), "LocalStorageVolume", true
}
});
- $.RawMethod(false, "setBlob", function (name, value) {
+ $.RawMethod(false, "setFileBytes", function (name, value) {
var key = getKey(this.name) + "_blobs_" + name;
var json = JSON.stringify(value);
View
39 Libraries/JSIL.ReadOnlyStorage.js
@@ -0,0 +1,39 @@
+"use strict";
+
+if (typeof (JSIL) === "undefined")
+ throw new Error("JSIL.Core required");
+
+if (typeof ($jsilstorage) === "undefined")
+ throw new Error("JSIL.Storage required");
+
+var $jsilreadonlystorage = JSIL.DeclareAssembly("JSIL.ReadOnlyStorage");
+
+JSIL.MakeClass($jsilstorage.TypeRef("VirtualVolume"), "ReadOnlyStorageVolume", true, [], function ($) {
+ $.RawMethod(false, ".ctor", function (name, rootPath, initializer) {
+ this.fileBytes = {};
+
+ VirtualVolume.prototype._ctor.call(
+ this, name, rootPath
+ );
+
+ initializer(this);
+ this.readOnly = true;
+ });
+
+ $.RawMethod(false, "flush", function () {
+ });
+
+ $.RawMethod(false, "getFileBytes", function (name) {
+ return this.fileBytes[name];
+ });
+
+ $.RawMethod(false, "setFileBytes", function (name, value) {
+ this.fileBytes[name] = value;
+ });
+
+ $.RawMethod(false, "toString", function () {
+ return "<ReadOnlyStorage Volume '" + this.name + "'>";
+ });
+});
+
+JSIL.ReadOnlyStorage = {};
View
50 Libraries/JSIL.Storage.js
@@ -9,6 +9,7 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualVolume", true, [], function ($)
$.RawMethod(false, ".ctor", function (name, rootPath, inodes) {
this.inodes = [];
this.name = name;
+ this.readOnly = false;
rootPath = this.normalizePath(rootPath);
@@ -124,6 +125,25 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualVolume", true, [], function ($)
return this.rootDirectory.enumerate(nodeType, searchPattern);
});
+ $.RawMethod(false, "enumerateFilesRecursive", function (searchPattern) {
+ var result = [];
+
+ var step = function (directory) {
+ var subdirs = directory.enumerate("directory");
+ for (var i = 0; i < subdirs.length; i++)
+ step(subdirs[i]);
+
+ var files = directory.enumerate("file", searchPattern);
+
+ for (var i = 0; i < files.length; i++)
+ result.push(files[i]);
+ };
+
+ step(this.rootDirectory);
+
+ return result;
+ });
+
$.RawMethod(false, "createDirectory", function (path) {
path = this.normalizePath(path);
@@ -156,12 +176,16 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualVolume", true, [], function ($)
return containingDirectory.createJunction(pieces[pieces.length - 1], targetObject, allowExisting);
});
- $.RawMethod(false, "createFile", function (path, allowExisting) {
+ $.RawMethod(false, "createFile", function (path, allowExisting, createParentDirectory) {
path = this.normalizePath(path);
var lastSlash = path.lastIndexOf("/"), parentDirectory, fileName;
if (lastSlash >= 0) {
- parentDirectory = this.rootDirectory.resolvePath(path.substr(0, lastSlash), true);
+ if (createParentDirectory)
+ parentDirectory = this.createDirectory(path.substr(0, lastSlash));
+ else
+ parentDirectory = this.rootDirectory.resolvePath(path.substr(0, lastSlash), true);
+
fileName = path.substr(lastSlash + 1);
} else {
parentDirectory = this.rootDirectory;
@@ -181,11 +205,11 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualVolume", true, [], function ($)
throw new Error("Not implemented");
});
- $.RawMethod(false, "getBlob", function (name) {
+ $.RawMethod(false, "getFileBytes", function (name) {
throw new Error("Not implemented");
});
- $.RawMethod(false, "setBlob", function (name, value) {
+ $.RawMethod(false, "setFileBytes", function (name, value) {
throw new Error("Not implemented");
});
@@ -280,6 +304,9 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualDirectory", true, [], function (
throw new Error("A file named '" + name + "' already exists.");
}
+ if (this.volume.readOnly)
+ throw new Error("The volume is read-only.");
+
return new VirtualFile(
this, this.volume.makeInode(this.inode, "file", name)
);
@@ -294,6 +321,9 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualDirectory", true, [], function (
throw new Error("A directory named '" + name + "' already exists.");
}
+ if (this.volume.readOnly)
+ throw new Error("The volume is read-only.");
+
return new VirtualDirectory(
this.volume, this, this.volume.makeInode(this.inode, "directory", name)
);
@@ -311,6 +341,9 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualDirectory", true, [], function (
if ((typeof (targetObject) !== "object") || (targetObject.type !== "directory"))
throw new Error("Target for junction must be a directory object");
+ if (this.volume.readOnly)
+ throw new Error("The volume is read-only.");
+
return new VirtualJunction(
this.volume, this, name, targetObject
);
@@ -390,7 +423,7 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualDirectory", true, [], function (
if (nodeType !== "directory") {
for (var k in this.files) {
if (predicate(k))
- result.push(k)
+ result.push(this.files[k]);
}
}
@@ -400,7 +433,7 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualDirectory", true, [], function (
continue;
if (predicate(k))
- result.push(k)
+ result.push(this.directories[k])
}
}
@@ -467,7 +500,7 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualFile", true, [], function ($) {
});
$.RawMethod(false, "readAllBytes", function () {
- var bytes = this.volume.getBlob(this.path);
+ var bytes = this.volume.getFileBytes(this.path);
this.inode.metadata.lastRead = Date.now();
@@ -480,7 +513,7 @@ JSIL.MakeClass($jsilcore.System.Object, "VirtualFile", true, [], function ($) {
$.RawMethod(false, "writeAllBytes", function (buffer, count) {
var bytes = Array.prototype.slice.call(buffer, 0, count);
- this.volume.setBlob(this.path, bytes);
+ this.volume.setFileBytes(this.path, bytes);
this.inode.metadata.lastWritten = Date.now();
this.inode.metadata.length = count;
@@ -558,6 +591,7 @@ JSIL.ImplementExternals("System.IO.FileStream", function ($) {
});
});
+
$jsilstorage.providers = [];
JSIL.RegisterStorageProvider = function (provider) {
View
33 Libraries/JSIL.XNAStorage.js
@@ -143,43 +143,44 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Storage.StorageContainer", func
}
);
- $.Method({Static:false, Public:true }, "GetDirectoryNames",
- (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [], [])),
- function GetDirectoryNames () {
+ $.RawMethod(false, "$getNames", function (nodeType, searchPattern) {
if (!this.volume)
return [];
- return this.volume.enumerate("directory");
+ var nodes = this.volume.enumerate(nodeType, searchPattern);
+ var result = [];
+
+ for (var i = 0; i < nodes.length; i++)
+ result.push(nodes[i].name);
+
+ return result;
+ });
+
+ $.Method({Static:false, Public:true }, "GetDirectoryNames",
+ (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [], [])),
+ function GetDirectoryNames () {
+ return this.$getNames("directory");
}
);
$.Method({Static:false, Public:true }, "GetDirectoryNames",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [$.String], [])),
function GetDirectoryNames (searchPattern) {
- if (!this.volume)
- return [];
-
- return this.volume.enumerate("directory", searchPattern);
+ return this.$getNames("directory", searchPattern);
}
);
$.Method({Static:false, Public:true }, "GetFileNames",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [], [])),
function GetFileNames () {
- if (!this.volume)
- return [];
-
- return this.volume.enumerate("file");
+ return this.$getNames("file");
}
);
$.Method({Static:false, Public:true }, "GetFileNames",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [$.String], [])),
function GetFileNames (searchPattern) {
- if (!this.volume)
- return [];
-
- return this.volume.enumerate("file", searchPattern);
+ return this.$getNames("file", searchPattern);
}
);
View
6 Libraries/JSIL.js
@@ -100,6 +100,12 @@ contentManifest["JSIL"] = [
);
}
+ if (config.readOnlyStorage) {
+ contentManifest["JSIL"].push(
+ ["Library", "JSIL.ReadOnlyStorage.js"]
+ );
+ }
+
if (config.localStorage) {
contentManifest["JSIL"].push(
["Library", "JSIL.LocalStorage.js"]
View
1  jsil.org/demos/Mannux/Mannux.html
@@ -15,6 +15,7 @@
webgl2d: true,
xna: 3,
winForms: true,
+ readOnlyStorage: true,
manifests: [
"Mannux.exe",
"Content.contentproj"
Please sign in to comment.
Something went wrong with that request. Please try again.