Created
August 3, 2017 06:35
-
-
Save kapitanluffy/4d6e4d5d6f02ab4922bbf3754dd0a728 to your computer and use it in GitHub Desktop.
stickyman - backup & restore sticky notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
SETLOCAL enableDelayedExpansion | |
where /q makecab | |
if %errorlevel% neq 0 ( | |
set combkp=copy /Y | |
set comrtr=copy /Y | |
) else ( | |
rem set combkp=certutil -f -encode | |
rem set comrtr=certutil -f -decode | |
set combkp=makecab | |
set comrtr=expand | |
) | |
:: local vars | |
set source=%appdata%\Microsoft\Sticky Notes | |
set timestamp= | |
set "tab= " | |
set nl=^& echo. | |
set backupsdir=%~dp0stickyman_backups | |
if not exist "%backupsdir%" ( | |
mkdir "%backupsdir%" | |
) | |
:: check file access | |
2>nul (>>"%source%\StickyNotes.snt" (call )) && (call ) || (goto filelocked) | |
:: create backup of original stickies | |
if not exist "%source%\StickyNotes.original.snt" ( | |
copy "%source%\StickyNotes.snt" "%source%\StickyNotes.original.snt">nul | |
) | |
if /I "%~1"=="restore" goto restore | |
if /I "%~1"=="backup" goto backup | |
if /I "%~1"=="list" goto listbackups | |
if /I "%~1"=="fresh" goto emptysticky | |
if "%~1"=="" goto help | |
:help | |
echo. | |
echo %~n0 restore^|backup^|list^|fresh [key] | |
echo. | |
echo Backups ^& Restores your sticky notes | |
echo Made by this guy: https://twitter.com/kapitanluffy | |
echo. | |
echo KEY%tab% Backup key for the sticky file. | |
echo RESTORE%tab% Restores a sticky file based on KEY. KEY defaults to "original" when unspecified. | |
echo BACKUP%tab% Backups a sticky file based on specified KEY. KEY defaults to current username [%username%] when unspecified. | |
echo LIST%tab% List backup sticky files. | |
echo FRESH%tab% Creates a fresh sticky notes | |
goto :listbackups | |
:listbackups | |
set count=0 | |
for /f %%i in ('dir /b /a-d %backupsdir%\*.sticky ^| find /c /v ""') do (set count=%%i) | |
if %count%==0 goto :eof | |
echo. | |
echo Backups found (%count%) | |
for /f %%a in ('dir /b /a-d %backupsdir%\*.sticky') do @echo - %%~na | |
goto :eof | |
:backup | |
if "%~2"=="" (set n=%username%) else (set n=%~2) | |
if exist "%backupsdir%\%n%.sticky" goto backupexist | |
%combkp% "%source%\StickyNotes.snt" "%backupsdir%\%n%.sticky">nul | |
rem certutil -f -encode "%backupsdir%\%n%.sticky_" "%backupsdir%\%n%.sticky">nul | |
rem del /q "%backupsdir%\%n%.sticky_" | |
echo Created %n% sticky notes backup | |
goto :eof | |
:restore | |
if "%~2"=="" (set n=original) else (set n=%~2) | |
if "%n%"=="original" goto restoreoriginal | |
if not exist "%backupsdir%\%n%.sticky" goto backupmiss | |
rem certutil -f -decode "%backupsdir%\%n%.sticky" "%backupsdir%\%n%.sticky_">nul | |
%comrtr% "%backupsdir%\%n%.sticky" "%source%\StickyNotes.snt">nul | |
rem del /q "%backupsdir%\%n%.sticky_" | |
echo Restored %n% sticky notes | |
goto :eof | |
:emptysticky | |
del /q "%source%\StickyNotes.snt" | |
echo Created new empty sticky notes | |
goto :eof | |
:restoreoriginal | |
copy "%source%\StickyNotes.original.snt" "%source%\StickyNotes.snt">nul | |
echo Restored original sticky notes | |
goto :eof | |
:backupexist | |
echo Backup for %n% sticky notes already exists | |
goto :eof | |
:backupmiss | |
echo Backup for %n% sticky notes does not exists | |
goto listbackups | |
:filelocked | |
echo Cannot access sticky notes. Please close sticky notes first | |
goto :eof | |
:timestamp | |
set d=%DATE:~4,10% | |
set t=%TIME:~0,7% | |
set timestamp=%d:/=%%t::=% | |
goto :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment