This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MKlegoman357's profile picture

Redfile - File Browser That Will Suit Your Needs(1.3) - Turning Into File Browser!

Started by MKlegoman357, 20 May 2013 - 03:16 PM
MKlegoman357 #1
Posted 20 May 2013 - 05:16 PM
Originally made for “CodeWars - Reloaded” contest, round 1. Second place :P/>

V1.3


RedFile

File browser with Rednet support

Download: XeZ2eaBx or

pastebin get XeZ2eaBx RedFile


This was originally made as Rednet file sender and manager but it turned out that this would be a great File Browser! So now I'm implementing all features that File Browser can have, like copy, cut, run with arguments, file info, open with, compile to show errors (real-time and not) and more… Suggestions are very appreciated (those who suggest something that I will implement are going to be added to Thank list).

From now this will be a File Browser so wait for all of the features I will add!


Features:
  • Open, edit, delete files
  • Send and receive files via Rednet
  • Close all open modems
  • Create folder/file
  • Supports advanced and normal computers
New features coming! Including:
    Remote file server and client system Copy, Move, Paste Run, Run with arguments Open with Delete Send, Receive files Create new Folder, File Check Program for errors Show error when program errors Double-click support Customize colors Default folder setting New function that will pop a new window in which you will be able to select a folder, file or a specific file.
Usage:
  • Open program, choose file with arrow keys or mouse and choose an option from menu
  • You can also run it with arguments (this allows to run it from another program):
1st argument: “get” or "send”.
2nd argument: - if you choose “send” then this is your client computer id, else if you choose “get” then, if given, it will wait for that computer, otherwise it will wait for any other computer.
3rd argument: - file path you want to send; only used when "send" is chosen.


--Sending myawsomeprogram to computer with id 14
shell.run("RedFile", "send", 14, "myawsomeprogram")

--Waiting for file from any computer
shell.run("RedFile", "get")

--Waiting for file from computer with id 10
shell.run("RedFile", "get", 10)


Screenshots:


Spoiler







Other screenshots:

Spoiler

















Bugs/To do:

Spoiler
  • Add function to wrap text - Done!
  • Improve small windows - Done!
  • Improve large windows - Done!
  • Add remote file server and client system - suggested by LDShadowLord
  • Make help more useful
  • Add "Color customization" option - suggested by AndyAndreiH
  • Add "File info" and "Settings" options
  • Add "Change default folder" option
  • Add "Open with.." option
  • Add "Run" and "Run with arg.." option
  • Add Function to let you select folder/file, if file then specific file
  • Add "Copy", "Cut", "Paste" options
  • Add Different dropdown menus on different files, folders (/rom, .nfp)
  • Add Separate Rednet function tab (Send, Receive, Close All modems)
  • Add Double click support
  • Add "Program options" option (Compiler, error checker - suggest!)
  • Show error when program errors
Bugs:
  • none
Suggest :)/>

Change log:

Spoiler1.3
  • Improved scrollbar rendering
  • Optimized code
  • Automatic program name when printing usage
  • Scrollbar is now clickable
1.2b
  • Fixed bug when using 1 modem: rednet:14 Invalid side
1.2
  • Added version to file browser
  • Added new function to format strings
  • Fixed bug when modems weren't closed
  • Optimized/made faster sending
  • Checking file size before getting a file
  • When getting a file you can see it's size
  • Added scrollbar to selection menus
1.1
  • Added full mouse support
  • Added new option: Close all modems
  • Added help
  • Improved selection menus
  • Fixed some bugs
1.0
  • Initial release

Older versions:

Spoiler

Thank list:

SpoilerIn here will be written all users that had helped me to develop this program, find bugs and make suggestions that were added. I thank for all these people.

License:

You can use and edit this program as long as you give me credits


Found bugs? Have suggestions?

Just post it as reply.
Edited on 11 May 2014 - 07:55 AM
Zudo #2
Posted 23 May 2013 - 03:09 AM
Looks good!
MKlegoman357 #3
Posted 23 May 2013 - 08:05 AM
Looks good!

Thanks!
masterdisasterHD #4
Posted 23 May 2013 - 02:18 PM
modem on top: rednet:14 Invalid side
MKlegoman357 #5
Posted 23 May 2013 - 03:26 PM
modem on top: rednet:14 Invalid side

Thank you for bug report!
I will fix it as fast as possible, maybe in 1 or 2 days, when I will release a newer version.

EDIT: Fixed, check out new version!
masterdisasterHD #6
Posted 26 May 2013 - 10:39 AM
yay fixed :D/>
MKlegoman357 #7
Posted 26 May 2013 - 11:16 AM
yay fixed :D/>

I just hate when my fans/program users have to wait ;)/>.
masterdisasterHD #8
Posted 27 May 2013 - 05:05 PM
Oh progress, i like progress :)/>
MKlegoman357 #9
Posted 02 June 2013 - 02:12 PM
Tell me if someone finds this program useful, if not I will not continue it, I am now creating my own os and have some other plans. Vote in the poll.

Decided to continue it's development as I'm still learning and this is a great learning experience.
ETHANATOR360 #10
Posted 02 June 2013 - 04:35 PM
this looks alot nicer then my unreleased one
MKlegoman357 #11
Posted 07 June 2013 - 03:57 PM
This was originally made as Rednet file sender and manager but it turned out that this would be a great File Browser! So now I'm implementing all features that File Browser can have, like copy, cut, run with arguments, file info, open with, compile to show errors (realtime and not) and more… Suggestions are very appreciated (those who suggest something that I will implement are going to be added to Thank list).
MKlegoman357 #12
Posted 25 June 2013 - 06:25 PM
I'm back from my trip to France. I have been there for about 3 weeks and didn't had any time to code, but now I have and I will try to update RedFile as soon as possible. Any feature you can think of that is a must-have file browser feature, please suggest it, I would be very thankful.

And for the new features:
What would be better to copy/move functions?
  • Copy or Cut, then at any time browse to desired folder and Paste. (like the Windows File Explorer)
or
  • When Copying or Moving a window pops out and you select desired folder immediately.

Vote in poll
Dave-ee Jones #13
Posted 27 June 2013 - 03:09 AM
Ahh, yes.

EDIT: You better hope the winner doesn't upload there's :P/>
masterdisasterHD #14
Posted 28 June 2013 - 02:44 PM
suggestion: password encrypted files
johnnic #15
Posted 02 July 2013 - 11:52 PM
Could anyone show me where in the code he handles when you click exit? i'm trying to use this in an OS and i want exit to bring you back to the desktop.

Thanks in advance
MKlegoman357 #16
Posted 03 July 2013 - 05:16 AM
Spoiler
--Selection menu made by MKlegoman357
local function selectionMenu(TableSelections, NumberKey, limit)
  local xO, yO = term.getCursorPos()
  local x, y = term.getCursorPos()
  local xm, ym = term.getCursorPos()
  local w, h = term.getSize()
  local selection = 1
  local pos = 1
  local enable = false

  limit = limit or #TableSelections

  local function scroll ()
    if selection < pos then
      pos = selection
    elseif selection > pos + limit - 1 then
      pos = selection - limit + 1
    end
  end

  while true do
  x, y = xO + 1, yO
  term.setCursorPos(x, y)

  scroll()

  for n = pos, getMin(#TableSelections, limit + pos - 1) do
    resetColors()

    if TableSelections[n] == "" then
      term.setCursorPos(x, y)
      term.write(TableSelections[n])
      y = y + 1
    elseif TableSelections[n] then
      term.setCursorPos(x, y)

      if selection == n then
        term.setBackgroundColor(conBColor(colors.blue))
        term.setTextColor(conTColor(colors.yellow))
      end

      term.write(TableSelections[n]) 
      y = y + 1
    end
  end

  resetColors()

  x, y = xO, yO
  term.setCursorPos(x, y)

  if #TableSelections > 1 then
    local b = limit < #TableSelections
    local limit = getMin(#TableSelections, limit)
    term.setBackgroundColor(conBColor(colors.blue))
    term.setTextColor(conTColor(colors.yellow))

    local start = getMax(round(pos / #TableSelections * limit), 1)
    local finish = getMin(start + getMax(round(limit / #TableSelections * limit), 1), limit)

    for n = start, finish do
      term.setCursorPos(x, y + n - 1)
      term.write(" ")
    end
  end

  local event, p1, x, y = os.pullEvent()

  if event == "key" then
    if p1 == keys.down then
      repeat
        selection = selection + 1
      until TableSelections[selection] ~= "" or selection <= 1
    elseif p1 == keys.up then
      repeat
        selection = selection - 1
      until TableSelections[selection] ~= "" or selection >= #TableSelections
    elseif p1 == keys.enter then
      return selection
    elseif NumberKey and p1 == NumberKey then
      return selection, true
    else
      x, y = xO, yO
      term.setCursorPos(x, y)
    end
  elseif event == "mouse_scroll" then
    if p1 < 0 then
      repeat
        selection = selection - 1
      until TableSelections[selection] ~= "" or selection >= #TableSelections
    else
      repeat
        selection = selection + 1
      until TableSelections[selection] ~= "" or selection <= 1
    end
  elseif event == "mouse_click" then
    local xw, yw = xO, yO
    xp, yp = xO, yO
    local ok = false

    enable = false

    for n = pos, getMin(#TableSelections, limit + pos - 1) do
      if y == yw and x >= xw + 1 and x <= xw + #TableSelections[n] then
        selection = n
        ok = true
        break
      end

      yw = yw + 1
    end

    if not ok then
      local limit = getMin(#TableSelections, limit)
      local start = getMax(round(pos / #TableSelections * (limit)), 1)
      local finish = getMin(start + getMax(round(limit / #TableSelections * limit), 1), limit)

      for n = start, finish do
        term.setCursorPos(xp, yp + n - 1)
        term.write(" ")

        if x == xp and y == yp + n - 1 then
          enable = true
          break
        end
      end
    end

    if ok == true and p1 == 1 then
      return selection
    elseif p1 == 2 then
      return selection, true
    end
  elseif event == "mouse_drag" and enable == true then
    local moved = clamp(y - ym, -1, 1)

    if moved > 0 then
      local limit = getMin(#TableSelections, limit)
      local start = getMax(round(pos / #TableSelections * limit), 1)
      local finish = getMin(start + getMax(round(limit / #TableSelections * limit), 1), limit) + 1

      local temp = round(finish / limit * #TableSelections)

      selection = temp
    else
      local limit = getMin(#TableSelections, limit)
      local start = getMax(round(pos / #TableSelections * limit), 1) - 1

      local temp = round(start / limit * #TableSelections)

      selection = temp
    end

    xm, ym = x, y
  end

  x, y = xO, yO
  term.setCursorPos(x, y)

  for n = pos, getMin(#TableSelections, limit + pos - 1) do
    if TableSelections[n] then
      resetColors()
      term.setCursorPos(x, y)
      term.write(string.rep(" ", #TableSelections[n] + 1))
      y = y + 1
    end
  end

  selection = clamp(selection, 1, #TableSelections)
  end
end

I use this as my selection menus. The exit button is last selection that you can click and if you click it it just exits the program.

PS: There are several functions in this code that I have written myself, like: clamp(), getMin(), getMax(), round(). And if you will use this code, give me Credits. :)/>
johnnic #17
Posted 03 July 2013 - 10:13 AM
I have given you credits, and thanks. Should be a big help.
johnnic #18
Posted 03 July 2013 - 10:35 AM
Could you show me exactly how to handle the exit click? Have been trying for a while now.
johnnic #19
Posted 03 July 2013 - 05:46 PM
Never mind. Got it figured out.
halo3sniperrifle #20
Posted 12 October 2013 - 09:41 PM
Nice Man! I hope this gets updated with the move file feature plus all those other features! Awesome, definitely going on my 5 star list!
You should also think of making a way so if someone sends you a file you don't have to be waiting for them to send it, it goes into a new folder that you should make.
MKlegoman357 #21
Posted 14 October 2013 - 03:45 PM
Hmm… I think I'm going to continue this program. It was dead to me, but as long as there will be someone who would like to use this I should not stop its development.
LDShadowLord #22
Posted 15 October 2013 - 11:11 AM
Would this be possible to re-design I wonder. To make an FTP style browser. I would love the ability to push and retrieve files from a remote computer. Would be very handy :)/>
MKlegoman357 #23
Posted 15 October 2013 - 01:58 PM
Would this be possible to re-design I wonder. To make an FTP style browser. I would love the ability to push and retrieve files from a remote computer. Would be very handy :)/>

The Idea with remote file server sounds attractive. I think I will add it in some form or another.
logsys #24
Posted 22 February 2014 - 08:57 AM
This will help me a bunch. Some other guys done stuff like this but not good as this
MKlegoman357 #25
Posted 22 February 2014 - 09:26 AM
This will help me a bunch. Some other guys done stuff like this but not good as this

Thank you very much :D/>/>. I personally use it a lot when I want to surf all the files faster than using 'cd' and 'ls' commands.

Hmm… I think I'm going to continue this program. It was dead to me, but as long as there will be someone who would like to use this I should not stop its development.

For everyone who cared I did continue development of this program. Almost all code was re-written, the main part was done. I would have released it but my computer crashed when I was coding it and I had to hard-restart it. After that my whole program was replaced by spaces and I didn't have any backup left, although I did knew that my code editor always makes backups of scripts but for some reason it didn't made one for my program :'(.
Edited on 22 February 2014 - 08:26 AM
logsys #26
Posted 22 February 2014 - 10:04 AM
For everyone who cared I did continue development of this program. Almost all code was re-written, the main part was done. I would have released it but my computer crashed when I was coding it and I had to hard-restart it. After that my whole program was replaced by spaces and I didn't have any backup left, although I did knew that my code editor always makes backups of scripts but for some reason it didn't made one for my program :'(.
I hope it doesn't die, this is an awesome program
Konlab #27
Posted 23 May 2014 - 12:47 PM
So, the update is cool.
I have some tip for you:
Open with..
SpoilerIf you want to open a program with 1. The user selects the program.
2.:
shell.run("selected program","path"), and if the selected program has anility to open files with path, then its working, if not it don't give errors, just runs the program.

Copy/paste:
Spoiler1.if a user clicks on 'copy' than filepath will be the path of copied file, and the filename is the filename of copied file.
2.to save the copied file's path:
var = fs.open(".Redfile/.copypath","w")
var.writeLine(filepath)
var.writeLine(filename)
var.close() --There must be var.close()!!!
3.paste-> your current path will be curpath
var = fs.open(".Redfile/.copypath","r")
filepath = readLine()
filename = readLine()
var.close()
fs.copy(filepath,curpath.."/"..filename)



I hope helped you!
Edited on 23 May 2014 - 10:57 AM
MKlegoman357 #28
Posted 24 May 2014 - 12:43 PM
-snip-

Well, development of this program was suspended because of the reason posted above and I'm not thinking about re-writing it anytime soon, probably never. As mentioned in the OP, this program was made for a contest, I don't even know why I posted it on the Programs subforum.