Added basic hexfile reading that respects r/w perms
This commit is contained in:
@@ -15,3 +15,4 @@
|
|||||||
//= require editor
|
//= require editor
|
||||||
//= require highlight
|
//= require highlight
|
||||||
//= require jquery-textcomplete
|
//= require jquery-textcomplete
|
||||||
|
//= require memory
|
||||||
|
|||||||
19
app/assets/javascripts/memory.js
Normal file
19
app/assets/javascripts/memory.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
$(function() {
|
||||||
|
var data = [];
|
||||||
|
$('td').keydown(function() {
|
||||||
|
data.push(this.id, $(this).html().substr(0, 2)); //position, value
|
||||||
|
})
|
||||||
|
$('td').blur(function() {
|
||||||
|
if ((id_i = data.indexOf(this.id) != -1) && data[id_i+1] != $(this).html().substr(0, 2)) {
|
||||||
|
var int_id = this.id.split("-")[1]
|
||||||
|
$.post("/memory/update_memory?project="+$(this).closest("table").data("project")+"&file="+Math.floor((int_id/2048)+1)+"&mem_id="+int_id%2048+"&value="+$(this).html().substr(0, 2));
|
||||||
|
data.splice(id_i, 2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('select').change(function() {
|
||||||
|
$.get("/memory/table?project="+$(this).data("project")+"&file="+$(this).find("option:selected").text()+".hex")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1027,3 +1027,10 @@ nav.pagination {
|
|||||||
border-radius: 0.2em;
|
border-radius: 0.2em;
|
||||||
text-shadow: none;
|
text-shadow: none;
|
||||||
}
|
}
|
||||||
|
.memory-table {
|
||||||
|
width: 870px;
|
||||||
|
margin: auto;
|
||||||
|
th, td {
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
BIN
app/controllers/.memory_controller.rb.swp
Normal file
BIN
app/controllers/.memory_controller.rb.swp
Normal file
Binary file not shown.
53
app/controllers/memory_controller.rb
Normal file
53
app/controllers/memory_controller.rb
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
class MemoryController < ApplicationController
|
||||||
|
|
||||||
|
before_filter :logged_in
|
||||||
|
|
||||||
|
def index
|
||||||
|
current_uuid = current_user.uuid.gsub("-", "")
|
||||||
|
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/players/#{current_uuid}")
|
||||||
|
psjson = JSON.parse(File.read("projects.json"))
|
||||||
|
@projects = psjson["owns"] + psjson["read"] + psjson["write"]
|
||||||
|
@project_names = @projects.collect{|p| (data = JSON.parse(File.read(File.expand_path("../..")+"/projects/#{p}/project.json")))["name"] + " | #{"own" if data["owner"] == current_uuid}#{"write" if data["write"].include? current_uuid}#{"read" if data["read"].include? current_uuid}"}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def list
|
||||||
|
render :index
|
||||||
|
end
|
||||||
|
|
||||||
|
def table
|
||||||
|
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project]}")
|
||||||
|
@data = []
|
||||||
|
Dir.glob('*').reverse.each do |f|
|
||||||
|
File.open(Dir.pwd+"/#{f}") do |file|
|
||||||
|
@data.concat(file.read.unpack("C*").map{|h| h.to_s(16)})
|
||||||
|
if JSON.parse((jf = File.open(Dir.pwd+"/project.json")).read)["read"].include? current_user.uuid.gsub("-","")
|
||||||
|
@can_edit = false
|
||||||
|
else
|
||||||
|
@can_edit = true
|
||||||
|
end
|
||||||
|
jf.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_memory
|
||||||
|
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project]}")
|
||||||
|
new_text = ""
|
||||||
|
File.open("#{params[:file]}.hex"){|f| new_text = f.read.unpack("C*").collect{|h| h.to_s(16)}}
|
||||||
|
new_text[params[:mem_id].to_i] = params[:value]
|
||||||
|
File.open("#{params[:file]}.hex", "w") do |f|
|
||||||
|
f.write((new_text.collect{|h| h.to_s.to_i(16)}).pack("C*").force_encoding("UTF-8"))
|
||||||
|
end
|
||||||
|
render nothing: true
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def logged_in
|
||||||
|
unless current_user
|
||||||
|
flash[:alert] = "Please log in before viewing memory files."
|
||||||
|
redirect_to home_statics_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
2
app/helpers/memory_helper.rb
Normal file
2
app/helpers/memory_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module MemoryHelper
|
||||||
|
end
|
||||||
4
app/views/memory/index.html.erb
Normal file
4
app/views/memory/index.html.erb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<%= form_tag "memory/table", method: :get do %>
|
||||||
|
<%= select_tag "project", options_for_select(@projects.collect.with_index{|p, i| [@project_names[i], p]}) %>
|
||||||
|
<%= submit_tag "View Table", name: nil %>
|
||||||
|
<% end %>
|
||||||
16
app/views/memory/table.html.erb
Normal file
16
app/views/memory/table.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<table class="memory-table", data-project="<%=params[:project]%>">
|
||||||
|
<tr>
|
||||||
|
<% ["Address","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"].each do |i| %>
|
||||||
|
<th><b><%=i%></b></th>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
<% @data.in_groups_of(16).each_with_index do |row, rindex| %>
|
||||||
|
<tr>
|
||||||
|
<td><b><%=(rindex*16).to_s(16).upcase.rjust(6, "0")%></b></td>
|
||||||
|
<% row.each_with_index do |hex, hindex| %>
|
||||||
|
<td contenteditable="<%=@can_edit%>" id="memory-<%=(16*rindex)+hindex%>"><%=hex.to_s.upcase.rjust(2, "0")%></td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
@@ -29,6 +29,15 @@ Redstoner::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :memory do
|
||||||
|
collection do
|
||||||
|
get 'list'
|
||||||
|
get 'table'
|
||||||
|
post 'update_memory'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
resources :forumgroups, path: '/forums/groups'
|
resources :forumgroups, path: '/forums/groups'
|
||||||
resources :forums, path: '/forums'
|
resources :forums, path: '/forums'
|
||||||
resources :forumthreads, path: '/forums/threads' do
|
resources :forumthreads, path: '/forums/threads' do
|
||||||
|
|||||||
Reference in New Issue
Block a user