Compare commits

..

No commits in common. "eee1b33454c088c78c0de2613b27488adf023b57" and "2f91b707117a640eedf3f88116338e02f8b3237b" have entirely different histories.

1 changed files with 22 additions and 77 deletions

View File

@ -2,8 +2,6 @@
-- tape managing program
-- made by LDDestroier
local _DEBUG = false
local function checkOption(argName, argInfo, isShort)
for i = 1, #argInfo do
if argInfo[i][isShort and 2 or 3] == argName then
@ -108,7 +106,6 @@ local function getHelp(specify)
print("mtape [-e --erase]")
print("mtape [-u --unclean]")
print("mtape [-c --cc-media]")
print("mtape [-u]")
print("Use -h with other options for details")
else
if specify == "--info" then
@ -119,35 +116,20 @@ local function getHelp(specify)
elseif specify == "--unclean" then
print("Normally, tapes are erased before writing them anew. Use this option to not erase them first.")
print("If the tape has something longer written to it beforehand, you'll hear it after whatever is written now.")
elseif specify == "--ldd-github" then
elseif specify == "--ldd-github" then
print("Adds URL info from LDDestroier's personal CC-Media github to make it easier to pull from there.")
print("Ex. 'tapey -c krabii'")
print(" 'tapey -c simple'")
elseif specify == "--reinstall" then
print("Updates Mtape to the latest version on the LDDestroier/CC github.")
end
end
end
local tierInfo = {
-- damage value indicates type of tape
-- value of tierInfo indicates minutes of storage
[0] = 4,
[1] = 8,
[2] = 16,
[3] = 32,
[4] = 64,
[5] = 2,
[6] = 6,
[8] = 128
}
local function getFileContents(path, isURL)
local file, contents
if isURL then
file = http.get(path, nil, true)
else
file = fs.open(fs.combine(shell.dir(), path), "rb")
file = fs.open(fs.combine(shell.dir(), path))
end
if not file then
return false, ""
@ -189,26 +171,14 @@ local function writeToTape(tape, contents, tapeName)
if tapeName then
tape.setLabel(tapeName)
end
tape.stop()
tape.seek(-tape.getPosition())
if #contents > totalTapeSize then
output = "Tape too small, audio truncated."
for i = 0, 8 do
if tierInfo[i] then
if tierInfo[i] * 360000 >= #contents then
output = output .. "\nIt would fit on a" .. (tierInfo[i] == 8 and "n " or " ") .. tostring(tierInfo[i]) .. " minute tape."
break
end
end
end
contents = contents:sub(1, totalTapeSize)
output = "Tape too small. Audio was written incompletely."
end
tape.write(contents)
tape.seek(-tape.getPosition())
tape.stop()
return output
end
local function infoMode(tape)
@ -222,6 +192,19 @@ local function infoMode(tape)
inserted = gi ~= nil
}
local tierInfo = {
-- damage value indicates type of tape
-- value of tierInfo indicates minutes of storage
[0] = 4,
[1] = 8,
[2] = 16,
[3] = 32,
[4] = 64,
[5] = 2,
[6] = 6,
[8] = 128
}
local minute = 360000
if not info.inserted then
@ -250,8 +233,7 @@ local argInfo = {
[3] = {1, "d", "drive"},
[4] = {0, "e", "erase"},
[5] = {0, "u", "unclean"},
[6] = {1, "c", "cc-media"},
[7] = {0, "r", "reinstall"}
[6] = {1, "c", "cc-media"}
}
local arguments, options, errors = argParse({...}, argInfo)
@ -273,7 +255,6 @@ local wantedInfo = options[2] == true
local wantedErase = options[4] == true
local doUnclean = options[5] == true
local getFromGithub = options[6][1]
local wantedUpdate = options[7] == true
if wantedHelp then
if wantedInfo then
@ -284,38 +265,12 @@ if wantedHelp then
getHelp("--unclean")
elseif getFromGithub then
getHelp("--ldd-github")
elseif wantedUpdate then
getHelp("--reinstall")
else
getHelp()
end
return
end
if wantedUpdate then
print("Redownloading Mtape...")
local cpath = shell.getRunningProgram()
local file = http.get("https://github.com/LDDestroier/CC/raw/master/mtape.lua")
local contents
local sizeBefore = fs.getSize(cpath)
local sizeAfter = 0
if file then
contents = file.readAll()
sizeAfter = #contents
file.close()
file = fs.open(cpath, "w")
file.write(contents)
file.close()
print("Done! (diff: " .. tostring(sizeAfter - sizeBefore) .. " bytes)")
return
else
print("Couldn't update.")
return
end
end
-- Try to wrap specified tape drive OR find tape drive
success, tape, totalTapeSize = getTapeDrive(tapeDriveName)
if not success then
@ -336,7 +291,6 @@ end
if getFromGithub then
print("Pulling from CC-Media.")
tapeName = arguments[1]
fileName = "https://github.com/LDDestroier/CC-Media/raw/master/DFPWM/" .. getFromGithub .. ".dfpwm"
end
@ -351,36 +305,27 @@ if fileName:sub(1,8) == "https://" then
success, contents = getFileContents(fileName, true)
print("Done.")
else
if not fs.exists(fileName) then
fileName = fileName .. ".dfpwm"
end
success, contents = getFileContents(fileName, false)
end
if not success then
error("Could not get file. Abort.")
else
if _DEBUG then
print("File size: " .. tostring(#contents) .. " bytes")
print("Tape size: " .. tostring(tape.getSize()) .. " bytes")
end
end
-- Adds null data to the end of the file if you want a clean tape write
if doUnclean then
print("Won't clean up tape first.")
else
contents = contents .. string.char(0):rep(math.max(0, totalTapeSize - #contents))
contents = contents .. string.char(0):rep(totalTapeSize - #contents)
end
write("Writing...")
print("Writing...")
success = writeToTape(tape, contents, tapeName)
if success then
print("\n" .. success)
print(success)
print("Nonetheless, it is written.")
else
print("done!")
print("\nIt is written.")
end
return true