StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Yuichi  
#1 Posted : Saturday, September 15, 2018 1:52:40 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 54
Poland

Thanks: 18 times
Was thanked: 18 time(s) in 13 post(s)
Hi
I just want to share with code because few times i crash program completely BigGrin

If you want to backup config file every time when you do any gesture just put this function to Global Actions -> Settings -> Before Action
and use it Global Actions -> Settings -> After Action.

Function copy main file and delete too old backup files.
n_range controls how many file must be saved.
If n_range is 10 and then you change it to 5 script will delete 5 oldest files.

I made this code under Win7 so the paths may not fit.


Code:
// BACKUP CONFIG
    function BackupConfigFile()
    {
        // FUNCTIONS
            function tInsert(arr, str) // table insert (as last item for one-dimensional table)
            {
                var size = arr.length;
                arr[size] = str;
                return arr;
            }

            function tReverse(arr) // reverse table
            {
                for(i = 0; i < arr.length / 2; i++)
                {
                    temp = arr[i];
                    arr[i] = arr[arr.length - i - 1];
                    arr[arr.length - i - 1] = temp;
                }
                return arr;
            }

        // GET FILES
            var t_files = [];
            var f_config_main = "";
            var f_config_backup = "";
            var files = clr.System.IO.Directory.GetFiles("C:\\Users\\" + sysinfo.UserName + "\\AppData\\Roaming\\StrokesPlus.net\\");
            for(var i = 0; i < files.Length; i++)
            {
                var file = new FileInfo(files[i]);
                var name = file.Name; // name
                var date_time = file.LastWriteTime; // date time
                //var size = file.Length; // size
                if(name == "StrokesPlus.net.bin") { f_config_main = date_time; } // only main file
                else  if(name != "StrokesPlus.net.bin") // get only backup files
                {
                    f_config_backup = date_time; // file with newest date
                    tInsert(t_files, name);
                }
            }

        // PATHS
            var date = DateTime.Now.ToString().replace(/:/g, "."); // file cannot be saved with ":" in name
            p_SPlusNetMainFile = "C:\\Users\\" + sysinfo.UserName + "\\AppData\\Roaming\\StrokesPlus.net\\StrokesPlus.net.bin"
            p_SPlusNetBackupFile = "C:\\Users\\" + sysinfo.UserName + "\\AppData\\Roaming\\StrokesPlus.net\\StrokesPlus.net " + date + ".bin"

        // BACKUP
            if(f_config_main != f_config_backup) // some changes are made
            {
                File.Copy(p_SPlusNetMainFile, p_SPlusNetBackupFile); // feel safety
                var n_range = 10 // how many file must be saved
                if(t_files.length >= n_range) // delete too old file(s)
                {
                    tReverse(t_files); // reverse table
                    for(var i = (n_range-1); i < t_files.length; i++)
                    {
                        File.Delete("C:\\Users\\" + sysinfo.UserName + "\\AppData\\Roaming\\StrokesPlus.net\\" + t_files[i]);
                    }
                }
            }
    }
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.