Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Card System Program with Automatic Disk ID Capture
- -- Function to list all cards in /disk/Cards
- local function listCards()
- local cardDir = "/disk/Cards/"
- local files = fs.list(cardDir)
- if #files > 0 then
- print("Cards in /disk/Cards:")
- for _, file in ipairs(files) do
- print("- " .. file)
- end
- else
- print("No cards found in /disk/Cards.")
- end
- end
- -- Function to link a card
- local function linkCard()
- while true do
- print("\nLink Card:")
- print("1. Insert Card to Link")
- print("2. Enter Card ID")
- print("0. Back to Main Menu")
- local choice = tonumber(read())
- if choice == 1 then
- print("Insert a disk to link...")
- local _, diskID = os.pullEvent("disk")
- diskID = diskID:gsub("%-", "") -- Remove dashes if present
- local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
- local file = fs.open(cardFileName, "w")
- file.close()
- print("Card linked successfully with ID: " .. diskID)
- elseif choice == 2 then
- print("Enter the card ID:")
- local cardID = read()
- local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
- local file = fs.open(cardFileName, "w")
- file.close()
- print("Card linked successfully.")
- elseif choice == 0 then
- break -- Back to main menu
- else
- print("Invalid choice. Please enter 1, 2, or 0.")
- end
- end
- end
- -- Function to unlink a card
- local function unlinkCard()
- while true do
- print("\nUnlink Card:")
- print("1. Insert Card to Unlink")
- print("2. Enter Card ID")
- print("0. Back to Main Menu")
- local choice = tonumber(read())
- if choice == 1 then
- print("Insert a disk to unlink...")
- local _, diskID = os.pullEvent("disk")
- diskID = diskID:gsub("%-", "") -- Remove dashes if present
- local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
- if fs.exists(cardFileName) then
- fs.delete(cardFileName)
- print("Card unlinked successfully for ID: " .. diskID)
- else
- print("No matching card found to unlink.")
- end
- elseif choice == 2 then
- print("Enter the card ID:")
- local cardID = read()
- local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
- if fs.exists(cardFileName) then
- fs.delete(cardFileName)
- print("Card unlinked successfully.")
- else
- print("No matching card found to unlink.")
- end
- elseif choice == 0 then
- break -- Back to main menu
- else
- print("Invalid choice. Please enter 1, 2, or 0.")
- end
- end
- }
- -- Main program loop
- while true do
- print("\nCard System")
- print("1. List Cards")
- print("2. Link Card")
- print("3. Unlink Card")
- print("0. Exit")
- local choice = tonumber(read())
- if choice == 1 then
- listCards()
- elseif choice == 2 then
- linkCard()
- elseif choice == 3 then
- unlinkCard()
- elseif choice == 0 then
- print("Exiting...")
- break
- else
- print("Invalid choice. Please enter a number from the menu.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement