Key Bindings Backup Script for Windows

Apps, websites, tools and helpers for Elite: Dangerous
User avatar
b00st3d
Novice
Novice
Posts: 80
Joined: Thu Feb 23, 2017 1:09 am
CMDR: b00st3d
CMDR_Platform: PC-MAC
Contact:

Key Bindings Backup Script for Windows

Postby b00st3d » Sat Feb 24, 2018 2:02 pm

Hello Cmdrs! I am by trade a system administrator, so any chance I get, I'll write a script or program to do something on a computer. With that said, version 3.0 coming soon so I wrote this to help you with backing up your keybindings. What it does is copies the content of the keybindings folder to a folder on your desktop, allows you to restore your keybindings folder by doing the same in reverse, and also has quick links to both locations.

TO USE THIS SCRIPT YOU MUST BE ON WINDOWS.
1.) Copy everything in the code tag below into a notepad.
2.) Save the notepad as keybindingbackup.bat (the name isn't nearly as important as the .bat)
3.) Launch the script and choose what you want to do. It gives you a menu.
4.) Profit?


Updated: Found an error where it was having trouble determining errorlevel when inside an if statement was allowing for a command to be canceled. Added setlocal enabledelayedexpansion in order to get around this issue.

keybindingbackup.bat

Code: Select all

@goto script
This script was written for the elite dangerous.  What it does is backup your current bindings to your desktop.  You will then be able to restore the backups to the game folder.  When backups are restored, it will backup the original folder then copy the backed up files into the game folder.
Author b00st3d@nrevolt.net
:script
@echo off&setlocal enabledelayedexpansion
cd %desktop%
set savepath="%userprofile%\desktop\BindingsBackup"
set bindings="%localappdata%\Frontier Developments\Elite Dangerous\Options\Bindings"
title Backup and Restore Elite Dangerous Bindings

:top
cls
echo Bindings location: 
echo %bindings%
echo.
echo Backup location:
echo %savepath%
echo.
echo.
echo ++++++++++++++++++++++++++++++++++++++++++++++++++
echo + This script will backup your bindings folder   +
echo + to your desktop.                               +
echo +                                                +
echo + 1. Backup bindings                             +
echo + 2. Restore bindings                            +
echo + 3. Open bindings folder                        +
echo + 4. Open backup folder                          +
echo +                                                +
echo + 5. Exit                                        +
echo +                                                +
echo ++++++++++++++++++++++++++++++++++++++++++++++++++
echo.
choice /C 12345 /N /M "Please enter a selection: "
if %errorlevel% == 1 goto backup
if %errorlevel% == 2 goto restore
if %errorlevel% == 3 start "" %bindings%&goto top
if %errorlevel% == 4 start "" %savepath%&goto top
REM if the user doesn't select 1-4 automatically exit.
exit
:backup
cls
REM check if the savepath exists
call :foldercheck %savepath%

REM if the folder exists then warn the user they are about to overwrite
if %errorlevel% == 1 (
   choice /C yn /N /M "Bindings have already been backed up.  Would you like to overwrite? [y,n]: "
   if !errorlevel! == 1 rd /s/q %savepath%\&md %savepath%
   if !errorlevel! == 2 goto top
) else (
REM if the folder doesn't exist then make it
   md %savepath% >nul
)     
REM copy the bindings to the new backup folder
xcopy /I /Q /S %bindings% %savepath%
echo.
echo Backup complete.
echo Backup is located on your desktop in the BindingsBackup folder
timeout 5 >nul
goto top

:restore
cls
REM check if the backup exists
call :foldercheck %savepath%
if %errorlevel% == 1 (
REM warn the user they are about to overwrite their current bindings with a backup

   echo If you continue your current bindings will be replaced by the bindings located in
   echo %userprofile%\desktop\BindingBackup. 
   echo.
   choice /c yn /n /m "Continue? [y,n]: "
   if !errorlevel! == 2 goto top
   if !errorlevel! == 1 (
      cd %bindings%
      cd ../
REM backup the current folder to Bindings.bak just in case
      xcopy /I /S Bindings Bindings.bak
REM delete the Bindings folder and everything in it
      rd /s/q Bindings
REM Create a new bindings folder and move the backup into it
      md Bindings
      xcopy /I /S %savepath% %bindings%
   )
) else (
      echo Error!  No backup located!
      timeout 3 >nul
      goto top
   )
goto top


REM This function comes from M. Jamal on https://stackoverflow.com/questions/138981/how-to-test-if-a-file-is-a-directory-in-a-batch-script
REM This function will return an errorlevel depending on whether the supplied folderpath is valid.
REM Errorlevel 0 means file/folder doesn't exist
REM Errorlevel 1 means exists, and it is a folder
REM Errorlevel 3 means exists, and it is a file
:foldercheck <path>
@pushd %~dp1
@if not exist "%~nx1" (
        popd
        exit /b 0
) else (
        if exist "%~nx1\*" (
                popd
                exit /b 1
        ) else (
                popd
                exit /b 3
        )
)
Last edited by b00st3d on Thu Jun 28, 2018 2:15 am, edited 7 times in total.

Skonkerz
Harmless
Harmless
Posts: 2
Joined: Fri Dec 29, 2017 2:18 pm
CMDR: Skonkerz
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby Skonkerz » Sat Feb 24, 2018 2:14 pm

This is very useful and confirmed as working perfectly! :D

Thank you CMDR

User avatar
b00st3d
Novice
Novice
Posts: 80
Joined: Thu Feb 23, 2017 1:09 am
CMDR: b00st3d
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby b00st3d » Sat Feb 24, 2018 3:05 pm

Glad you like it Skonkerz. I'm also looking for critiques. If you see something wrong with the script or something that should be done differently, please feel free to bring it up.

User avatar
Hengest
Novice
Novice
Posts: 71
Joined: Wed Feb 11, 2015 12:21 pm
CMDR: Hengest
CMDR_Platform: None Specified
Contact:

Re: Key Bindings Backup Script for Windows

Postby Hengest » Sat Feb 24, 2018 3:36 pm

Excellent, worked perfectly.

Thank you
Image

LeDoyen
Expert
Expert
Posts: 342
Joined: Fri Jul 28, 2017 7:48 pm
CMDR: Le Doyen
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby LeDoyen » Sat Feb 24, 2018 6:35 pm

pretty handy with 3.0 being only days away

User avatar
GreenViper
Master
Master
Posts: 953
Joined: Mon May 01, 2017 3:21 pm
CMDR: GreenViper
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby GreenViper » Sat Feb 24, 2018 8:36 pm

Handy indeed, thanks CMDR !
- Cmdr GreenViper -

Forum moderator
MCRN Flight group leader & Council member


Image

Mobius Colonial Republic Navy
:arrow:Arriving in Colonia, first check our MCRN status page for daily updated info on where carto data is needed.

cussine
Harmless
Harmless
Posts: 4
Joined: Wed Sep 07, 2016 8:55 pm
CMDR: cussine
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby cussine » Tue Feb 27, 2018 10:10 am

Thank You, should be made a sticky :)
My God it's full of Stars !!!!

User avatar
Judson
Master
Master
Posts: 727
Joined: Thu Nov 13, 2014 4:39 pm
CMDR: Judson
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby Judson » Tue Feb 27, 2018 11:15 am

Thank you very neat and simple. A bit like me! :p
Image
Image

User avatar
b00st3d
Novice
Novice
Posts: 80
Joined: Thu Feb 23, 2017 1:09 am
CMDR: b00st3d
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby b00st3d » Tue Feb 27, 2018 2:17 pm

Found an error in the script and updated. The error I found was when you try to cancel an action, it would ask for permission then go ahead with the action regardless of the user's choice. This was caused by not having delayed expansion enabled. Without delayed expansion, when a statement is evaluated, it doesn't update until after the statement is complete. With delayed expansion, I can enter a statement, change a value and have the change reflect immediately.

here is an example of how that works for those that care about batch scripting

Code: Select all

@echo off&setlocal enabledelayedexpansion

set test=1

if %test% == 1 (
   echo %test%
   set /p test="Please enter a new value: "
   echo.
   echo.
   echo with delayedexpansion disabled
   echo %test%
   pause
   echo.
   echo.
   echo with delayedexpansion enabled
   echo !test!
   pause
)

User avatar
Judson
Master
Master
Posts: 727
Joined: Thu Nov 13, 2014 4:39 pm
CMDR: Judson
CMDR_Platform: PC-MAC
Contact:

Re: Key Bindings Backup Script for Windows

Postby Judson » Tue Feb 27, 2018 2:44 pm

Added with permission to the OoM Inara wing documents. Thanks again Cmdr b00st3d
Image
Image


Return to “Tools and Helpers”

Who is online

Users browsing this forum: No registered users and 1 guest

i