Advertisement
DOGGYWOOF

Untitled

Jun 17th, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. -- Card System Program with Automatic Disk ID Capture
  2.  
  3. -- Function to list all cards in /disk/Cards
  4. local function listCards()
  5. local cardDir = "/disk/Cards/"
  6. local files = fs.list(cardDir)
  7. if #files > 0 then
  8. print("Cards in /disk/Cards:")
  9. for _, file in ipairs(files) do
  10. print("- " .. file)
  11. end
  12. else
  13. print("No cards found in /disk/Cards.")
  14. end
  15. end
  16.  
  17. -- Function to link a card
  18. local function linkCard()
  19. while true do
  20. print("\nLink Card:")
  21. print("1. Insert Card to Link")
  22. print("2. Enter Card ID")
  23. print("0. Back to Main Menu")
  24. local choice = tonumber(read())
  25.  
  26. if choice == 1 then
  27. print("Insert a disk to link...")
  28. local _, diskID = os.pullEvent("disk")
  29. diskID = diskID:gsub("%-", "") -- Remove dashes if present
  30.  
  31. local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
  32. local file = fs.open(cardFileName, "w")
  33. file.close()
  34.  
  35. print("Card linked successfully with ID: " .. diskID)
  36. elseif choice == 2 then
  37. print("Enter the card ID:")
  38. local cardID = read()
  39.  
  40. local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
  41. local file = fs.open(cardFileName, "w")
  42. file.close()
  43.  
  44. print("Card linked successfully.")
  45. elseif choice == 0 then
  46. break -- Back to main menu
  47. else
  48. print("Invalid choice. Please enter 1, 2, or 0.")
  49. end
  50. end
  51. end
  52.  
  53. -- Function to unlink a card
  54. local function unlinkCard()
  55. while true do
  56. print("\nUnlink Card:")
  57. print("1. Insert Card to Unlink")
  58. print("2. Enter Card ID")
  59. print("0. Back to Main Menu")
  60. local choice = tonumber(read())
  61.  
  62. if choice == 1 then
  63. print("Insert a disk to unlink...")
  64. local _, diskID = os.pullEvent("disk")
  65. diskID = diskID:gsub("%-", "") -- Remove dashes if present
  66.  
  67. local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
  68. if fs.exists(cardFileName) then
  69. fs.delete(cardFileName)
  70. print("Card unlinked successfully for ID: " .. diskID)
  71. else
  72. print("No matching card found to unlink.")
  73. end
  74. elseif choice == 2 then
  75. print("Enter the card ID:")
  76. local cardID = read()
  77.  
  78. local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
  79. if fs.exists(cardFileName) then
  80. fs.delete(cardFileName)
  81. print("Card unlinked successfully.")
  82. else
  83. print("No matching card found to unlink.")
  84. end
  85. elseif choice == 0 then
  86. break -- Back to main menu
  87. else
  88. print("Invalid choice. Please enter 1, 2, or 0.")
  89. end
  90. end
  91. }
  92.  
  93. -- Main program loop
  94. while true do
  95. print("\nCard System")
  96. print("1. List Cards")
  97. print("2. Link Card")
  98. print("3. Unlink Card")
  99. print("0. Exit")
  100.  
  101. local choice = tonumber(read())
  102.  
  103. if choice == 1 then
  104. listCards()
  105. elseif choice == 2 then
  106. linkCard()
  107. elseif choice == 3 then
  108. unlinkCard()
  109. elseif choice == 0 then
  110. print("Exiting...")
  111. break
  112. else
  113. print("Invalid choice. Please enter a number from the menu.")
  114. end
  115. end
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement