support multi file import with file0_name
This commit is contained in:
parent
ed674f2cdb
commit
9885853cea
|
@ -129,6 +129,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
|
|||
<li class="dropdown dropdown-submenu">
|
||||
<a tabindex="-1" href="#">Tools</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" target="_8bws_tools" href="//8bitworkshop.com/dithertron/">Dithertron Image Converter</a></li>
|
||||
<li><a class="dropdown-item" target="_8bws_tools" href="//8bitworkshop.com/bitmapfontgenerator/">Bitmap Font Generator</a></li>
|
||||
<li><a class="dropdown-item" target="_8bws_tools" href="http://tomeko.net/online_tools/file_to_hex.php?lang=en">Binary File to Hex Converter</a></li>
|
||||
<li class="dropdown dropdown-submenu">
|
||||
|
|
|
@ -1,82 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
// TODO: use modules; export type for LocalForageDbMethods
|
||||
//import * as localforage from "localforage";
|
||||
// TODO: don't need this file anymore?
|
||||
|
||||
declare var localforage;
|
||||
|
||||
var Ver2xFileStore = function(storage, prefix:string) {
|
||||
var self = this;
|
||||
this.saveFile = function(name, text) {
|
||||
storage.setItem(prefix + name, text);
|
||||
}
|
||||
this.loadFile = function(name) {
|
||||
return storage.getItem(prefix + name) || storage.getItem(name);
|
||||
}
|
||||
this.getFiles = function(prefix2) {
|
||||
// iterate over files with <platform>/<dir> prefix
|
||||
var files = [];
|
||||
for (var i = 0; i < storage.length; i++) {
|
||||
var key = storage.key(i);
|
||||
if (key.startsWith(prefix + prefix2)) {
|
||||
var name = key.substring(prefix.length + prefix2.length);
|
||||
files.push(name);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
this.deleteFile = function(name) {
|
||||
storage.removeItem(prefix + name);
|
||||
}
|
||||
}
|
||||
|
||||
// copy localStorage to new driver
|
||||
function copyFromVer2xStorageFormat(storeid:string, newstore, callback:(store)=>void) {
|
||||
var alreadyMigratedKey = "__migrated_" + storeid;
|
||||
//localStorage.removeItem(alreadyMigratedKey);
|
||||
if (localStorage.getItem(alreadyMigratedKey)) {
|
||||
callback(newstore);
|
||||
return;
|
||||
}
|
||||
var oldstore = new Ver2xFileStore(localStorage, storeid + '/');
|
||||
var keys = oldstore.getFiles('');
|
||||
// no files to convert?
|
||||
if (keys.length == 0) {
|
||||
localStorage.setItem(alreadyMigratedKey, 'true');
|
||||
callback(newstore);
|
||||
return;
|
||||
}
|
||||
// convert function
|
||||
function migrateNext() {
|
||||
var key = keys.shift();
|
||||
var value = oldstore.loadFile(key);
|
||||
newstore.setItem(key, value, function(err, result) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log("Converted " + key);
|
||||
if (keys.length) {
|
||||
migrateNext();
|
||||
} else {
|
||||
newstore.length(function(err, len) {
|
||||
if (err) throw err;
|
||||
console.log("Migrated " + len + " local files to new data store");
|
||||
if (len) {
|
||||
localStorage.setItem(alreadyMigratedKey, 'true');
|
||||
callback(newstore);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
migrateNext(); // start the conversion
|
||||
}
|
||||
|
||||
export function createNewPersistentStore(storeid:string, callback:(store)=>void) {
|
||||
export function createNewPersistentStore(storeid:string) {
|
||||
var store = localforage.createInstance({
|
||||
name: "__" + storeid,
|
||||
version: 2.0
|
||||
});
|
||||
copyFromVer2xStorageFormat(storeid, store, callback);
|
||||
return store;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import { Platform, Preset, DebugSymbols, DebugEvalCondition, isDebuggable, EmuSt
|
|||
import { PLATFORMS, EmuHalt, Toolbar } from "../common/emu";
|
||||
import * as Views from "./views";
|
||||
import { createNewPersistentStore } from "./store";
|
||||
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG,
|
||||
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, stringToByteArray,
|
||||
byteArrayToUTF8, isProbablyBinary, getWithBinary, getBasePlatform, getRootBasePlatform, hex } from "../common/util";
|
||||
import { StateRecorderImpl } from "../common/recorder";
|
||||
import { GHSession, GithubService, getRepos, parseGithubURL } from "./services";
|
||||
|
@ -498,7 +498,7 @@ function importProjectFromGithub(githuburl:string, replaceURL:boolean) {
|
|||
}
|
||||
// create new store for imported repository
|
||||
setWaitDialog(true);
|
||||
var newstore = createNewPersistentStore(urlparse.repopath, () => { });
|
||||
var newstore = createNewPersistentStore(urlparse.repopath);
|
||||
// import into new store
|
||||
setWaitProgress(0.25);
|
||||
return getGithubService().import(githuburl).then( (sess1:GHSession) => {
|
||||
|
@ -1941,6 +1941,29 @@ function loadImportedURL(url : string) {
|
|||
}, 'text');
|
||||
}
|
||||
|
||||
async function loadFormDataUpload() {
|
||||
setWaitDialog(true);
|
||||
for (var i=0; i<20; i++) {
|
||||
let path = qs['file'+i+'_name'];
|
||||
let dataenc = qs['file'+i+'_data'];
|
||||
if (path == null || dataenc == null) break;
|
||||
let value = dataenc;
|
||||
if (qs['file'+i+'_type'] == 'binary') {
|
||||
value = stringToByteArray(atob(value));
|
||||
}
|
||||
var olddata = await store.getItem(path);
|
||||
if (!olddata || confirm("Replace existing file '" + path + "'?")) {
|
||||
await store.setItem(path, value); // TODO: alert when replacing?
|
||||
if (i == 0) { qs['file'] = path; } // set main filename
|
||||
}
|
||||
delete qs['file'+i+'_name'];
|
||||
delete qs['file'+i+'_data'];
|
||||
delete qs['file'+i+'_type'];
|
||||
}
|
||||
setWaitDialog(false);
|
||||
replaceURLState();
|
||||
}
|
||||
|
||||
function setPlatformUI() {
|
||||
var name = platform.getPlatformName && platform.getPlatformName();
|
||||
var menuitem = $('a[href="?platform='+platform_id+'"]');
|
||||
|
@ -1952,7 +1975,7 @@ function setPlatformUI() {
|
|||
}
|
||||
|
||||
// start
|
||||
export function startUI() {
|
||||
export async function startUI() {
|
||||
// import from github?
|
||||
if (qs['githubURL']) {
|
||||
importProjectFromGithub(qs['githubURL'], true);
|
||||
|
@ -1989,15 +2012,18 @@ export function startUI() {
|
|||
setupSplits();
|
||||
// create store
|
||||
store_id = repo_id || getBasePlatform(platform_id);
|
||||
store = createNewPersistentStore(store_id, (store) => {
|
||||
// is this an importURL?
|
||||
if (qs['importURL']) {
|
||||
loadImportedURL(qs['importURL']);
|
||||
return;
|
||||
}
|
||||
// load and start platform object
|
||||
loadAndStartPlatform();
|
||||
});
|
||||
store = createNewPersistentStore(store_id);
|
||||
// is this an importURL?
|
||||
if (qs['importURL']) {
|
||||
loadImportedURL(qs['importURL']);
|
||||
return; // TODO: make async
|
||||
}
|
||||
// is this a file POST?
|
||||
if (qs['file0_name']) {
|
||||
await loadFormDataUpload();
|
||||
}
|
||||
// load and start platform object
|
||||
loadAndStartPlatform();
|
||||
}
|
||||
|
||||
async function loadAndStartPlatform() {
|
||||
|
|
Loading…
Reference in New Issue