SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 151 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function main(...)
  2.     require "libbl"
  3.     require "libsteam"
  4.     require "util.io"
  5.     require "util.table"
  6.  
  7.     if loadfile("steam2backloggery.cfg") then
  8.         loadfile("steam2backloggery.cfg")()
  9.     end
  10.  
  11.     -- initialize Steam
  12.     local path = STEAM or io.prompt("Steam location (drag-and drop steam.exe): ")
  13.  
  14.     local steam,err = steam.open(path:gsub('^"(.*)"$', '%1'))
  15.     if not steam then
  16.         io.eprintf("Couldn't read Steam directory: %s\n", err)
  17.         return 1
  18.     end
  19.  
  20.     io.printf("Found Steam account %s\n\n", tostring(steam))
  21.  
  22.     -- initialize Backloggery
  23.     local user = USER or io.prompt("Backloggery username: ")
  24.     local pass = PASS or io.prompt("Backloggery password: ")
  25.  
  26.     local cookie,err = bl.login(user,pass)
  27.  
  28.     if not cookie then
  29.         io.eprintf("Couldn't log in: %s\n", err)
  30.         return 1
  31.     else
  32.         io.printf("Logged in to Backloggery as %s.\n\n", user)
  33.     end
  34.  
  35.     io.printf("Loading Steam game lists:"); io.flush()
  36.     io.printf(" games"); io.flush(); steam:games()
  37.     io.printf(" wishlist"); io.flush(); steam:wishlist()
  38.  
  39.     if table.getn(steam:games()) == 0 and table.getn(steam:wishlist()) == 0 then
  40.         io.printf("\nFound no entries in Games or wishlist.\nThis is most likely due your profile not set public,\nso check your profile privacy settings!\n")
  41.         return 1
  42.     end
  43.  
  44.     io.printf(" done.\nLoading Backloggery game lists:"); io.flush()
  45.     io.printf(" games"); io.flush(); cookie:games()
  46.     io.printf(" wishlist"); io.flush(); cookie:wishlist()
  47.     io.printf(" done.\n\n")
  48.  
  49.     io.printf("Filtering games:"); io.flush()
  50.     local games = {}
  51.     local count = 0
  52.     for _,game in pairs(steam:games()) do
  53.         count = count+1
  54.         if not cookie:hasgame(game.name) then
  55.             games[#games+1] = {
  56.                 name = game.name;
  57.                 status = "unfinished";
  58.             }
  59.         end
  60.     end
  61.     io.printf(" %d owned games,", count); io.flush(); count = 0
  62.     for _,game in pairs(steam:wishlist()) do
  63.         count = count+1
  64.         if not cookie:hasgame(game.name) then
  65.             games[#games+1] = {
  66.                 name = game.name;
  67.                 status = "wishlist";
  68.             }
  69.         end
  70.     end
  71.     io.printf(" %d wishlisted games,", count); io.flush()
  72.     io.printf(" %d games to add.\n\n", #games)
  73.  
  74.     io.output("backloggery.txt")
  75.     io.write [[
  76. # This is a list of all of the games steam2backloggery is going to add to your
  77. # backloggery account.
  78. #
  79. # Please edit this list as you see fit, then save and exit. In particular, you
  80. # probably want to check the following:
  81. #
  82. # * change "unfinished" to "beaten", "completed", "mastered", or "null" as needed
  83. # * delete DLC from the list
  84. #
  85. # Lines starting with '#' will be ignored.
  86. #
  87. # If you decide that you've made a terrible mistake and don't want to upload
  88. # *anything* to your backloggery account, just erase everything in this file
  89. # and then save and exit.
  90. #
  91. ]]
  92.     for _,game in ipairs(games) do
  93.         io.printf("%-16s%s\n", game.status, game.name)
  94.     end
  95.     io.close()
  96.  
  97.     io.output(io.stdout)
  98.     io.printf("Launching editor so you can can review the game list..."); io.flush()
  99.     if os.execute("notepad backloggery.txt") > 0 then
  100.         io.eprintf("\nError executing editor! Aborting.")
  101.         return 1
  102.     end
  103.     io.printf("done.\n\n")
  104.  
  105.     local platform = CONSOLE
  106.     while not bl.platforms[platform] do
  107.         platform = io.prompt("Enter a Backloggery category (recommended: PC, PCDL, or Steam): ")
  108.     end
  109.  
  110.     -- now, we read the contents of the edited file so that we can upload the games
  111.     -- to backloggery.
  112.     io.printf("\nUpdating your Backloggery.\n")
  113.     for line in io.lines("backloggery.txt") do
  114.         local status,name = line:match("^(%w+)%s+(.*)")
  115.         if status and name then
  116.             local wishlist
  117.             if status == "wishlist" then
  118.                 status = "unfinished"
  119.                 wishlist = 1
  120.             end
  121.  
  122.             if not bl.completecode(status) then
  123.                 io.eprintf("Warning: skipping game '%s': unknown status '%s'\n", name, status)
  124.             else
  125.                 local r,e = cookie:addgame {
  126.                     name = name:trim();
  127.                     console = platform;
  128.                     complete = status;
  129.                     wishlist = wishlist;
  130.                 }
  131.                 if r then
  132.                     io.printf("Added %s game '%s'%s\n", status, name, wishlist and " to wishlist" or "")
  133.                 else
  134.                     io.printf("Couldn't add '%s': %s\n", name, e)
  135.                 end
  136.             end
  137.         end
  138.     end
  139.  
  140.     io.printf("Backloggery updated. Have a nice day!\n")
  141. end
  142.  
  143. local r,e = xpcall(main, debug.traceback)
  144. if not r then
  145.     io.eprintf("An error occurred! Please report this to the developer.\n%s\n", e)
  146. end
  147.  
  148. os.remove("backloggery.txt")
  149. io.printf("\nPress enter to quit...\n")
  150. io.read()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top