Jump to content

How copy/paste save folder with Lua?


James Deschênes

Recommended Posts

My mod contain only this file:

 

AutoSave = {}

local isToSave = 0;
local quickSaverKey = nil;

AutoSave.save = function()
	if isToSave == 0 then
		isToSave = 1;
		
		local player = getSpecificPlayer(0);
		player:Say("Wait a moment...");
		
		local tmpGmSpdVal = getGameSpeed();
		setGameSpeed(0);
		local tmpNonoSave = getCore():isNoSave();
		getCore():setNoSave(false);

		saveGame();
		
		local savesTable = getLatestSave();
		local saveFolder = savesTable[2] .. "/" .. savesTable[1];
		local absoluteSavePath = getAbsoluteSaveFolderName(saveFolder);
		local saveIterator = 2;
		
		while checkSaveFolderExists(saveFolder .. "_" .. tostring(saveIterator)) do
			saveIterator = saveIterator + 1;
		end
		
		-- TODO! All I need to do is to found a method that can I use to copy/paste save folder to other folder.
		-- THIS PART OF THE CODE IS NOT WORKING :
		--if isSystemWindows() then
		--	os.execute("robocopy " .. absoluteSavePath .. " " .. absoluteSavePath .. "_" .. tostring(saveIterator) .. " /E /NP /NFL /tee /R:1 /W:1 /MIR");
		--else
		--	os.execute("cp -ar " .. absoluteSavePath .. " " .. absoluteSavePath .. "_" .. tostring(saveIterator));
		--end

		getCore():setNoSave(tmpNonoSave);
		setGameSpeed(tmpGmSpdVal);
		
		player:Say("Game saved in " .. saveFolder .. "_" .. tostring(saveIterator));
		
		isToSave = 0;
	end
end

AutoSave.onKeyDn = function(keyDn)
	if keyDn == quickSaverKey then
		--print("AutoSave onKeyDn ok");
		AutoSave.save();
	end
end

AutoSave.init_mod = function()
	quickSaverKey = getCore():getKey("quickSaverKey");
	Events.OnKeyPressed.Add(AutoSave.onKeyDn);
end

AutoSave.init_keyBinds = function()
	table.insert(keyBinding, { value = "[AutoSave]" } );
	table.insert(keyBinding, { value = "quickSaverKey", key = 8 } );
end

Events.OnGameBoot.Add(AutoSave.init_keyBinds);
Events.OnLoad.Add(AutoSave.init_mod);

I need to copy the current save folder to a new folder.

Exemple, My save is in C:\Users\myuser\Zomboid\Saves\Sandbox\mysave\...
I need to copy this folder in C:\Users\myuser\Zomboid\Saves\Sandbox\mysave_2\...

Does a method exist or a function that I can use from Project Zomboid Java Class to make a copy/paste?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...