Log In  


I usually keep all my carts in a specific folder in Picotron, but it's annoying having to cd into that folder every time I want to load a cart, or type the whole path out. I'd rather just be able to load carts from that folder from anywhere in the filesystem.

So, I made loadcart. It's like load (and even uses load to do the actual loading), but you can run it from anywhere and it'll always load from a folder you specify. (It will default to /desktop if you don't set a folder.)

Let's say /desktop/carts is where you store all your carts. You'd run loadcart -d /desktop/carts at some point to set loadcart's saved folder. Now, from that points on, from anywhere in your filesystem, you can type loadcart mycart and it would be the same as running load /desktop/carts/mycart.p64.

Here's the contents of the .lua file. Just save it to /appdata/system/util/loadcart.lua. When you run it with the -d switch, the saved folder will be set in /appdata/loadcart.pod.

--[[
	For loading carts from a specific
	saved folder.
]]

function print_usage()
	print("\f6usage:\t\tloadcart filename\n\t\t\t\tcan be file or directory\n")
	print("\f6\t\t\tloadcart -d directory_name\n\t\t\t\tsets carts directory (defaults to \"/desktop\")\n")
	if (fstat("/appdata/loadcart.pod")) then
		local meta = fetch_metadata("/appdata/loadcart.pod")
		if (fstat(meta.dir) == "folder") then
			print("\f6current: "..meta.dir)
		else
			print("\f6current: /desktop")
		end
	else
		print("\f6current: /desktop")
	end
end

--show help
local e = env()
local argv = e.argv
if (#argv < 1 or #argv > 2) then
	print_usage()
	exit(1)
end

--load cart based on settings or default to /desktop
if (#argv == 1) then
	if (argv[1] == "-d") print_usage() exit(1)

	local dir = "/desktop"
	if (fstat("/appdata/loadcart.pod") == "file") then
		local meta = fetch_metadata("/appdata/loadcart.pod")
		if (meta.dir and fstat(meta.dir) == "folder") then
			dir = meta.dir
		else
			print("\f6invalid directory setting, defaulting to /desktop")
		end
	end
	cd(dir)
	create_process("/system/util/load.lua",
		{
			print_to_proc_id = e.print_to_proc_id,
			argv = {fullpath(argv[1])}
		}
	)
	exit(0)

elseif (#argv == 2) then
	cd(e.path)
	if (argv[1] == "-d") then
		local directory = fullpath(argv[2])
		if (fstat(directory) == "folder") then
			store("/appdata/loadcart.pod","",{title="loadcart utility settings",dir=directory})
			print("\f6loadcart set to: "..directory)
			exit(0)
		else
			print("invalid directory")
			exit(1)
		end
	else
		print_usage()
		exit(1)
	end
end
8



[Please log in to post a comment]