adds version checking for cave story, to ensure folders are valid

This commit is contained in:
duncathan 2020-03-06 06:28:38 -06:00
parent e52e63f8e8
commit 67adcb6639
3 changed files with 28 additions and 12 deletions

View file

@ -0,0 +1 @@
1

View file

@ -1,6 +1,7 @@
require 'lib.strict' require 'lib.strict'
VERSION = '0.8C' VERSION = '0.8C'
CSVERSION = 1
Class = require 'lib.classic' Class = require 'lib.classic'
_ = require 'lib.moses' _ = require 'lib.moses'
@ -26,8 +27,8 @@ function love.load()
Settings:init() Settings:init()
Screen:setup() Screen:setup()
if Settings.settings.csdirectory ~= "" then if Settings.settings.csdirectory == "csdata" then
Screen:setStatus("Cave Story folder found!") Screen:setStatus("Cave story folder found!")
Randomizer:setPath(Settings.settings.csdirectory) Randomizer:setPath(Settings.settings.csdirectory)
else else
Screen:setStatus("Drag and drop your Cave Story folder here.") Screen:setStatus("Drag and drop your Cave Story folder here.")
@ -62,15 +63,23 @@ local function recursivelyDelete( item )
end end
function love.directorydropped(path) function love.directorydropped(path)
local success = Randomizer:_mountDirectory(path) local success, dirStage = Randomizer:_mountDirectory(path)
local csversion = lf.read(dirStage .. '/_version.txt') or "0"
csversion = tonumber(csversion)
--Randomizer:_unmountDirectory(path) --Randomizer:_unmountDirectory(path)
if success then if success then
recursivelyDelete('csdata') -- completely clear the folder, in case of user error :) if csversion >= CSVERSION then
recursiveWrite('mounted-data', 'csdata') recursivelyDelete('csdata') -- completely clear the folder, in case of user error :)
Settings.settings.csdirectory = 'csdata' recursiveWrite('mounted-data', 'csdata')
Settings:update()
Randomizer:setPath('csdata') Settings.settings.csdirectory = 'csdata'
Screen:setStatus("Cave Story folder updated!") Settings.settings.csversion = csversion
Settings:update()
Randomizer:setPath('csdata')
Screen:setStatus("Cave Story folder updated!")
else
Screen:setStatus("Invalid Cave Story folder!\n\nMake sure you're using an up to date version of the randomizer's included Cave Story folder.")
end
else else
Screen:setStatus("Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?") Screen:setStatus("Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?")
end end

View file

@ -11,6 +11,10 @@ function C:init()
self.settings[k] = self.settings[k] or v self.settings[k] = self.settings[k] or v
end end
end end
-- check for out of date CS folder
if self.settings.csversion < CSVERSION then
self.settings.csdirectory = nil
end
self:update() self:update()
end end
@ -34,7 +38,8 @@ function C:getDefaults()
}, },
musicShuffle = false, musicShuffle = false,
musicBeta = false, musicBeta = false,
musicFlavor = "Shuffle" musicFlavor = "Shuffle",
csversion = 0
} }
end end
@ -53,7 +58,7 @@ function C:serialize()
local line = "return {\r\n" local line = "return {\r\n"
local tab = " " local tab = " "
line = line .. tab .. ("csdirectory = [[%s]],\r\n"):format(self.settings.csdirectory or "") line = line .. tab .. ("csdirectory = %q,\r\n"):format(self.settings.csdirectory or "")
line = line .. tab .. ("puppy = %s,\r\n"):format(self.settings.puppy) line = line .. tab .. ("puppy = %s,\r\n"):format(self.settings.puppy)
line = line .. tab .. ("obj = %q,\r\n"):format(self.settings.obj or "") line = line .. tab .. ("obj = %q,\r\n"):format(self.settings.obj or "")
line = line .. tab .. ("mychar = %q,\r\n"):format(self.settings.mychar or "") line = line .. tab .. ("mychar = %q,\r\n"):format(self.settings.mychar or "")
@ -63,7 +68,8 @@ function C:serialize()
line = line .. tab .. ("dboosts = %s,\r\n"):format(dboost) line = line .. tab .. ("dboosts = %s,\r\n"):format(dboost)
line = line .. tab .. ("musicShuffle = %s,\r\n"):format(self.settings.musicShuffle) line = line .. tab .. ("musicShuffle = %s,\r\n"):format(self.settings.musicShuffle)
line = line .. tab .. ("musicBeta = %s,\r\n"):format(self.settings.musicBeta) line = line .. tab .. ("musicBeta = %s,\r\n"):format(self.settings.musicBeta)
line = line .. tab .. ("musicFlavor = %q\r\n"):format(self.settings.musicFlavor) line = line .. tab .. ("musicFlavor = %q,\r\n"):format(self.settings.musicFlavor)
line = line .. tab .. ("csversion = %s,\r\n"):format(self.settings.csversion)
return line .. "}" return line .. "}"
end end