-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSynchronizer.ps1
182 lines (151 loc) · 4.36 KB
/
Synchronizer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
############################## GLOBALS ##############################
$global:debug = 0
$global:display = 'Normal'
$global:title = 'Synchronizer'
$global:args = $args
############################## VARIABLES ##############################
if (-not (Test-Path env:cr)) { $env:cr = 'C:\CR' }
$setupsPath = "$env:cr\Programs\Setups"
$portablesPath = "$env:cr\Programs\Portables"
############################## MAIN CODE ##############################
function main {
show_title $global:title -set_title
Write-Host -NoNewLine "`n`n You are about to run the $global:title, do you want to continue? [y/n] "
do {
$user_choice = [console]::ReadKey($TRUE).Key
if ($user_choice -eq 'N') { exit }
} until ($user_choice -eq 'Y')
''
sync @{
registry = @(
@{
title = '7-Zip (64-bit)'
path = 'HKCU\SOFTWARE\7-Zip'
backup = "$setupsPath\7-Zip (64-bit)\.7-Zip Settings -CR.reg"
},
@{
title = 'Internet Download Manager'
path = 'HKCU\SOFTWARE\DownloadManager'
backup = "$setupsPath\Internet Download Manager\.Internet Download Manager Settings -CR.reg"
},
@{
title = 'Cheat Engine'
path = 'HKCU\SOFTWARE\Cheat Engine'
backup = "$portablesPath\Cheat Engine\.Cheat Engine Settings -CR.reg"
}
)
files = @(
@{
title = 'AnyDesk'
path = "$env:AppData\AnyDesk\user.conf"
backup = "$portablesPath\AnyDesk\.AnyDesk Settings -CR\user.conf"
}
)
folders = @(
@{
title = 'GitHub Desktop'
path = "$env:AppData\GitHub Desktop"
backup = "$setupsPath\GitHub Desktop\.GitHub Desktop Settings -CR\GitHub Desktop"
},
@{
title = 'Chrome (64-bit)'
path = "$env:LocalAppData\Google\Chrome\User Data"
backup = "$setupsPath\Chrome (64-bit)\.Chrome Settings -CR\User Data"
exclude = 'BrowserMetrics Cache "Code Cache" GPUCache CacheStorage optimization_guide_prediction_model_downloads'
},
@{
title = 'Thunderbird (64-bit)'
path = "$env:AppData\Thunderbird\Profiles\ln02bahd.default-esr"
backup = "$setupsPath\Thunderbird (64-bit)\.Thunderbird Settings -CR\ln02bahd.default-esr"
}
)
}
Write-Host -NoNewLine "`n`n`t Running Beyond Compare... "
Start-Process "$portablesPath\Beyond Compare (64-bit)\BCompare.exe" 'Unique'
check_mark
finish
}
############################## FUNCTIONS ##############################
function show_title {
param (
[Parameter(Mandatory)] [string] $title,
[switch] $set_title
)
if ($set_title) { $Host.UI.RawUI.WindowTitle = $title }
Write-Host "`n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $title ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
}
function finish {
param (
[string] $title = 'Process Finished',
[switch] $restart
)
''
show_title $title
[system.media.systemsounds]::Beep.play()
if ($restart) {
Write-Host -ForegroundColor Yellow -NoNewline "`n`n`t`t Restarting is required, restart now? [y/n] "
do {
$user_choice = [console]::ReadKey($TRUE).Key
} until (@('Y', 'N') -contains $user_choice)
if ($user_choice -eq 'Y') {
Start-Process 'shutdown' '/t /t 0'
}
}
else {
Write-Host -ForegroundColor Yellow "`n`n`t`t`t (Press any key to exit)"
$NULL = [Console]::ReadKey($TRUE)
}
exit
}
function list_item {
param (
[Parameter(Mandatory)] [string] $text,
[string] $symbol = '-'
)
Write-Host -NoNewLine -ForegroundColor Gray "`n`t $symbol $text "
}
function check_mark {
param (
[string] $symbol = 'v',
[string] $color = 'Green'
)
Write-Host -ForegroundColor $color $symbol
}
function sync {
param ([Parameter(Mandatory)] [System.Collections.Hashtable] $syncs)
"`n`n`t Registry:"
$syncs.registry | ForEach-Object {
list_item $_.title
if (Test-Path ($_.path -Replace '^(.+?)\\', '$1:\')) {
Start-Process 'reg' "export ""$($_.path)"" ""$($_.backup)"" /y" -WindowStyle 'Hidden' -Wait
check_mark
}
else {
check_mark 'x' 'Red'
}
}
"`n`n`t Files:"
$syncs.files | ForEach-Object {
list_item $_.title
if (Test-Path $_.path -PathType 'Leaf') {
Copy-Item $_.path $_.backup
check_mark
}
else {
check_mark 'x' 'Red'
}
}
"`n`n`t Folders:"
$syncs.folders | ForEach-Object {
list_item $_.title
if (Test-Path $_.path -PathType 'Container') {
Start-Process 'robocopy' "`"$($_.path)`" `"$($_.backup)`" /MIR /XD $($_.exclude)" -WindowStyle 'Hidden' -Wait
check_mark
}
else {
check_mark 'x' 'Red'
}
}
}
############################## RUN MAIN CODE ##############################
main