can browse uploaded binary (.bin) files

This commit is contained in:
Steven Hugg 2018-12-01 04:45:55 -05:00
parent 385cb7acc2
commit c2eb32ce35
2 changed files with 66 additions and 4 deletions

View File

@ -136,15 +136,22 @@ function refreshWindowList() {
var mode = tool && TOOL_TO_SOURCE_STYLE[tool];
return new Views.SourceEditor(path, mode);
}
function addEditorItem(id:string) {
var data = current_project.getFile(id);
if (typeof data === 'string')
addWindowItem(id, getFilenameForPath(id), loadEditor);
else if (data instanceof Uint8Array)
addWindowItem(id, getFilenameForPath(id), () => { return new Views.BinaryFileView(data as Uint8Array); });
}
// add main file editor
var id = main_file_id;
addWindowItem(id, getFilenameForPath(id), loadEditor);
addEditorItem(main_file_id);
// add other source files
current_project.iterateFiles(function(id, text) {
if (text && id != main_file_id)
addWindowItem(id, getFilenameForPath(id), loadEditor);
addEditorItem(id);
});
// add listings
@ -198,7 +205,8 @@ function loadProject(preset_id:string) {
if (err) {
alert(err);
} else if (result && result.length) {
// we need this to build create functions for the editor (TODO?)
// we need this to build create functions for the editor
// TODO: can't use binary file as main
refreshWindowList();
// show main file
projectWindows.createOrShow(preset_id);

View File

@ -710,3 +710,57 @@ export class MemoryView implements ProjectView {
return i;
}
}
///
export class BinaryFileView implements ProjectView {
memorylist;
maindiv : HTMLElement;
data;
constructor(data:Uint8Array) {
this.data = data;
}
createDiv(parent : HTMLElement) {
var div = document.createElement('div');
div.setAttribute("class", "memdump");
parent.appendChild(div);
this.showMemoryWindow(parent, div);
return this.maindiv = div;
}
showMemoryWindow(workspace:HTMLElement, parent:HTMLElement) {
this.memorylist = new VirtualList({
w: $(workspace).width(),
h: $(workspace).height(),
itemHeight: getVisibleEditorLineHeight(),
totalRows: ((this.data.length+15) >> 4),
generatorFn: (row : number) => {
var s = this.getMemoryLineAt(row);
var linediv = document.createElement("div");
linediv.appendChild(document.createTextNode(s));
return linediv;
}
});
$(parent).append(this.memorylist.container);
}
getMemoryLineAt(row : number) : string {
var offset = row * 16;
var n1 = 0;
var n2 = 16;
var s = hex(offset+n1,4) + ' ';
for (var i=0; i<n1; i++) s += ' ';
if (n1 > 8) s += ' ';
for (var i=n1; i<n2; i++) {
var read = this.data[offset+i];
if (i==8) s += ' ';
s += ' ' + (read>=0?hex(read,2):' ');
}
return s;
}
refresh() {
}
}