This App is No Longer Maintained. Visit the Replacement at StrokesPlus.net

StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 Backup your config!
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rob

USA
2615 Posts

Posted - 12/06/2012 :  09:18:08  Show Profile  Visit Rob's Homepage
Ok, so people have mistakenly overwritten their config file (StrokesPlus.xml) which contains ALL gestures, settings, actions, etc.

Adding this code to your Global Lua will create a backup of the file in a folder you specify:
function BackupConfig(source, destination)
	local BUFSIZE = 2^14;
	local fInHandle = io.open(source, "rb");
	local fOutHandle = io.open(destination, "wb");
	local current = fInHandle:seek()      -- get current position
	local size = fInHandle:seek("end")    -- get file size
	fInHandle:seek("set", current)        -- restore position
	local blocks = math.floor(size / BUFSIZE);
	local remainder = size - (blocks * BUFSIZE);
	for i = 1, blocks do
		data = fInHandle:read(BUFSIZE);
		fOutHandle:write(data);
		pos = 1000 * i * BUFSIZE / size;
	end
	if (remainder > 0) then
		data = fInHandle:read(remainder);
		fOutHandle:write(data);
	end
	fInHandle:close();
	fOutHandle:close();
end

local sBackupFolder = "L:\\Development\\StrokesPlusConfigBackups\\"
BackupConfig("StrokesPlus.xml", sBackupFolder.."StrokesPlus.xml_"..os.date("%Y-%m-%d_%H%M%S"))

This would save based on year, month, day, hour, minute, and second, and would run anytime you click Apply or OK in the Settings window, when you click Reload Config and Lua Engine from the tray, or start S+.

Now, that's going to create a lot of files, but will certainly make sure you don't lose anything =)

You can change the last line of the code the only save once per day (will just overwrite the existing file for the same day, so it will always save the most recent of that day):
BackupConfig("StrokesPlus.xml", sBackupFolder.."StrokesPlus.xml_"..os.date("%Y-%m-%d"))

Or only once per month (same rules apply, would overwrite the existing backup during the same month):
BackupConfig("StrokesPlus.xml", sBackupFolder.."StrokesPlus.xml_"..os.date("%Y-%m"))

Or you can come up with your own format. Also notice that the backup is a function and I'm calling it from Global Lua, this could be moved into an action (the last two lines of the code block above), where it's only backed up when you execute the action.

You get the idea, this is just a starting point, but is fully functional. Just make sure that the backup path (folder and file name) has any special characters escaped (like \ as \\, " as \", etc.) and the folder must exist or you will get an error.

Rob

USA
2615 Posts

Posted - 12/06/2012 :  09:36:32  Show Profile  Visit Rob's Homepage
Also see this post for always using your config/global lua files from a specific location.
Go to Top of Page

Rob

USA
2615 Posts

Posted - 12/06/2012 :  16:23:48  Show Profile  Visit Rob's Homepage
Additionally, it would seem calling the function CopyFile instead of BackupConfig makes more sense. The function just copies a file from source to destination.
Go to Top of Page

athmalan

India
4 Posts

Posted - 10/17/2013 :  17:05:34  Show Profile
Hi rob ..when i copy paste this at the end of global lua and click on apply i get an error saying:
"attempt to handle local Fin/handle(nil value)"
Seems the error is in the 3rd line

quote:
Originally posted by Rob

Additionally, it would seem calling the function CopyFile instead of BackupConfig makes more sense. The function just copies a file from source to destination.

Go to Top of Page

Rob

USA
2615 Posts

Posted - 10/17/2013 :  17:18:07  Show Profile  Visit Rob's Homepage
It would seem to me that it's not finding or loading the input (config) file.

Have you tried fully qualifying the path and file name? For example "C:\\Users\\Rob\\AppData\\Roaming\\StrokesPlus\\StrokesPlus.xml"

..just to see if that works.

What is the exact line you have for BackupConfig call?

Note that my code above will need the last two lines changed based on your local system and where the files are.
Go to Top of Page

athmalan

India
4 Posts

Posted - 10/17/2013 :  17:48:02  Show Profile
Ok I don't think I understand what I have to do... I'm a noob
I changed the local sfolder to some folder of my choice say c://downloads//backup //" and left rest of the code as is..

Could you please elaborate step by step...

quote:
Originally posted by Rob

It would seem to me that it's not finding or loading the input (config) file.

Have you tried fully qualifying the path and file name? For example "C:\\Users\\Rob\\AppData\\Roaming\\StrokesPlus\\StrokesPlus.xml"

..just to see if that works.

What is the exact line you have for BackupConfig call?

Note that my code above will need the last two lines changed based on your local system and where the files are.

Go to Top of Page

Rob

USA
2615 Posts

Posted - 10/19/2013 :  12:49:32  Show Profile  Visit Rob's Homepage
It's very difficult for me to provide step-by-step instructions when I'm not at your computer :-/

The error seems to indicate that it's not finding the input file, which likely means the path isn't correct. But I can't say for certain. Really, you'd need to do some debugging to find the problem. Unfortunately, there's no easy way to describe those steps as there are a number of things that could be going on in your situation.

You could try using Process Monitor (filtering on StrokesPlus.exe only) to see what files/file paths the script is trying to access and see if it's showing FILE NOT FOUND messages.

You may also want to trying throwing up an acMessageBox(source)/acMessageBox(destination) inside the BackupConfig function to confirm the paths looks right.

While S+ can certainly be used without having a scripting/programming background, it's definitely an app where the end user benefits from greatly having a certain amount of technical experience.

Let me know what you're able to find or if there's anything specific I can try to assist you with.

Go to Top of Page

mesersmith

Romania
45 Posts

Posted - 10/24/2013 :  13:33:50  Show Profile
Hi Rob,

Today I descovered your soft, and it is very nice, but until now I worked with another mouse gesture software, and almost all my gesture was very different.
So, I had to modify every gesture.

I almost did, and I think if I put a fresh copy of windows, all my work goes to hell.
How can I save all my config?
The code above is to hard for me. Is there a simple solution?
Go to Top of Page

Rob

USA
2615 Posts

Posted - 10/24/2013 :  13:38:45  Show Profile  Visit Rob's Homepage
The easiest way is to simply backup your StrokesPlus.xml file. That holds all of your gestures, actions, and preferences.

Depending on how you installed and run S+, the StrokesPlus.xml file will be either in the same folder as StrokesPlus.exe, or in your appdata folder, e.g.:

C:\Users\{YOUR USERNAME}\AppData\Roaming\StrokesPlus

As long as you have your StrokesPlus.xml file, you can install S+ and replace it with your backup.
Go to Top of Page

mesersmith

Romania
45 Posts

Posted - 10/24/2013 :  13:41:31  Show Profile
Thanks a lot. I'll do that.
Go to Top of Page

mdx

3 Posts

Posted - 01/30/2014 :  02:43:02  Show Profile
I can confirm that providing the full path solves the error. The last two lines of the script then look like this:

local sBackupFolder = "C:\\Users\\mdx\\Documents\\BAK\\StrokesPlus\\"
BackupConfig("C:\\Users\\mdx\\AppData\\Roaming\\StrokesPlus\\StrokesPlus.xml", sBackupFolder.."StrokesPlus.xml_"..os.date("%Y-%m-%d"))

quote:
Originally posted by athmalan

Ok I don't think I understand what I have to do... I'm a noob
I changed the local sfolder to some folder of my choice say c://downloads//backup //" and left rest of the code as is..

Could you please elaborate step by step...

quote:
Originally posted by Rob

It would seem to me that it's not finding or loading the input (config) file.

Have you tried fully qualifying the path and file name? For example "C:\\Users\\Rob\\AppData\\Roaming\\StrokesPlus\\StrokesPlus.xml"

..just to see if that works.

What is the exact line you have for BackupConfig call?

Note that my code above will need the last two lines changed based on your local system and where the files are.



Go to Top of Page

Keely

3 Posts

Posted - 03/23/2014 :  11:41:03  Show Profile
i coudn't run S+.
Reason that my xml had problem.
so changed defualt xml. it was solved.

anyway my all settings dead.
I want to knwo why this happen to me. T.T
Go to Top of Page

Rob

USA
2615 Posts

Posted - 03/23/2014 :  12:49:29  Show Profile  Visit Rob's Homepage
I wish I had an explanation for you

There are many potential causes, like if S+ (or Windows) crashed during writing, but there's no way I could determine. I do know that you're the first person to ever post about this happening, so I can't imagine it's something wrong within S+, in the almost 3 years of my working on S+, the only times I've ever had the XML file become corrupt was because I was testing the code that writes the XML and S+ crashed or when I was working on the config simple encryption (password protection) feature.

Go to Top of Page

Keely

3 Posts

Posted - 03/24/2014 :  15:39:52  Show Profile
Thanks for reply Rob!

I read your explanation. but i coudnt understand T.T

My xml (problem file)
https://www.dropbox.com/s/yvrmd1uua554gsu/StrokesPlus.xml

Edited by - Keely on 03/24/2014 16:36:38
Go to Top of Page

babakm

58 Posts

Posted - 04/18/2014 :  11:46:55  Show Profile
it is work for me. thanks a lot.

function BackupConfig(source, destination)
local BUFSIZE = 2^14;
local fInHandle = io.open(source, "rb");
local fOutHandle = io.open(destination, "wb");
local current = fInHandle:seek() -- get current position
local size = fInHandle:seek("end") -- get file size
fInHandle:seek("set", current) -- restore position
local blocks = math.floor(size / BUFSIZE);
local remainder = size - (blocks * BUFSIZE);
for i = 1, blocks do
data = fInHandle:read(BUFSIZE);
fOutHandle:write(data);
pos = 1000 * i * BUFSIZE / size;
end
if (remainder > 0) then
data = fInHandle:read(remainder);
fOutHandle:write(data);
end
fInHandle:close();
fOutHandle:close();
end
local sBackupFolder = "G:\\Dropbox\\Backup\\StrokesPlus\\"
BackupConfig("C:\\Users\\bm\\AppData\\Roaming\\StrokesPlus\\StrokesPlus.xml", sBackupFolder.."StrokesPlus.xml_"..os.date("%Y-%m-%d"))
Go to Top of Page

Strokeman

33 Posts

Posted - 09/28/2014 :  10:06:17  Show Profile
quote:
Originally posted by Keely

i coudn't run S+.
Reason that my xml had problem.
so changed defualt xml. it was solved.

anyway my all settings dead.
I want to knwo why this happen to me. T.T


And it happened with me too . Bad i know.
Strokeplus showed up in process explorer but without any window. I changed the Strokeplus.Xml with basic xml and then it worked.
I didn't even have a bad shutdown

Anyway somehow i recovered my training and gestures from old xml file.
You can try Difference feature...something like this site. https://www.diffchecker.com/diff
Just put working XML on left and corrupt XML on right. Then try making a new XML using the data. Most of the time the issue is with the configuration settings which are on in top portion of XML. Mine was also some config issue
VERY HANDY and helped me re-make my XML file, even though took some time

I am now going to use this backup feature or regularly manually going to backup
I advise all to regularly backup XML. It can happen to you too and you will lose all your training and gestures if so. Better safe than sorry, especially if you are power user

Edited by - Strokeman on 09/28/2014 10:08:04
Go to Top of Page

OMAR

Mexico
4 Posts

Posted - 10/12/2015 :  22:34:17  Show Profile
I did it in this way, so each time you start the program makes a copy of the data:

if acGetNumber()==0 then acSetNumber(1)
io.input(io.open("StrokesPlus.xml","r"))
Data=io.read("*all")
File="C:\\Users\\Omar\\Google Drive\\S+ Backups\\StrokesPlus.xml"..os.date(" %d-%m-%Y %H;%M;%S")
io.output(io.open(File,"w"))
io.write(Data)
io.close()
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000