@@ -13,11 +13,12 @@ import (
13
13
"time"
14
14
15
15
"github.com/h2non/filetype"
16
+ "github.com/jessevdk/go-flags"
16
17
"github.com/ricochet2200/go-disk-usage/du"
17
18
)
18
19
19
20
const (
20
- softVersion = "1.1 "
21
+ softVersion = "1.2 "
21
22
dumpDir = "dump"
22
23
)
23
24
@@ -198,19 +199,76 @@ func freeStorage(path string) {
198
199
return
199
200
}
200
201
202
+ // Slice search
203
+ func searchSlice (y []string , z string ) bool {
204
+ for _ , n := range y {
205
+ if z == n {
206
+ return true
207
+ }
208
+ }
209
+ return false
210
+ }
211
+
201
212
// Initialisation of system information variables
202
213
var uid int
203
214
var userName string
204
215
var homePath string
205
216
var sudoerUID int
206
217
207
218
func main () {
208
- fmt .Print ("\n " )
219
+
220
+ fmt .Println ()
221
+
222
+ // Discord client build names
223
+ discordBuildName := map [int ]string {
224
+ 0 : "Stable" ,
225
+ 1 : "PTB" ,
226
+ 2 : "Canary" ,
227
+ 3 : "Development" ,
228
+ }
229
+ // Discord client build folder names
230
+ discordBuildDir := map [int ]string {
231
+ 0 : "discord" ,
232
+ 1 : "discordptb" ,
233
+ 2 : "discordcanary" ,
234
+ 3 : "discorddevelopment" ,
235
+ }
236
+ // Cache paths for each platform
237
+ cachePath := map [string ]string {
238
+ "linux" : "%s/.config/%s/Cache/" ,
239
+ "darwin" : "%s/Library/Application Support/%s/Cache/" ,
240
+ "windows" : "%s\\ AppData\\ Roaming\\ %s\\ Cache\\ " ,
241
+ }
242
+
243
+ // Initialise a few maps
244
+ pathStatus := make (map [int ]bool )
245
+ cachedFile := make (map [int ]map [int ]string )
246
+
247
+ // Initialise flags
248
+ var discordBuildListSlice []string
249
+ var discordBuildListOption string
250
+ var discordBuildListEntryName string
251
+ var discordBuildListEntryDir string
252
+
253
+ for i := 0 ; i < len (discordBuildName ); i ++ {
254
+ discordBuildListSlice = append (discordBuildListSlice , strings .ToLower (discordBuildName [i ]))
255
+ }
256
+
257
+ var opts struct {
258
+ Build string `short:"b" long:"build" description:"Select build type: stable, ptb, canary, development"`
259
+ Noninteractive bool `short:"n" long:"noninteractive" description:"Non-interactive -- no 'enter' key required"`
260
+ }
261
+
262
+ _ , err := flags .Parse (& opts )
263
+
264
+ if err != nil {
265
+ os .Exit (0 )
266
+ }
209
267
210
268
// Banner
211
- fmt .Print ("####################################### \n " )
269
+ fmt .Print ("#####################################\n " )
212
270
fmt .Printf ("# Discord Cache Dump :: Version %s #\n " , softVersion )
213
- fmt .Print ("####################################### \n \n " )
271
+ fmt .Print ("#####################################\n \n " )
214
272
215
273
user , err := user .Current ()
216
274
if err != nil {
@@ -275,6 +333,29 @@ func main() {
275
333
}
276
334
277
335
fmt .Printf ("Logged in as: %s\n \n " , userName )
336
+ // Build flag
337
+ if opts .Build != "" {
338
+ discordBuildListOption = strings .ToLower (opts .Build )
339
+ if ! searchSlice (discordBuildListSlice , discordBuildListOption ) {
340
+ fmt .Printf ("[ERROR] Build type does not exist %s" , exitNewLine ())
341
+ os .Exit (1 )
342
+ } else {
343
+ fmt .Printf ("Build selected: %s\n \n " , discordBuildListOption )
344
+ for i := 0 ; i < len (discordBuildDir ); i ++ {
345
+ if discordBuildListOption == strings .ToLower (discordBuildName [i ]) {
346
+ discordBuildListEntryName = discordBuildName [i ]
347
+ discordBuildListEntryDir = discordBuildDir [i ]
348
+ break
349
+ }
350
+ }
351
+ discordBuildName = map [int ]string {
352
+ 0 : discordBuildListEntryName ,
353
+ }
354
+ discordBuildDir = map [int ]string {
355
+ 0 : discordBuildListEntryDir ,
356
+ }
357
+ }
358
+ }
278
359
279
360
fmt .Print ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n " )
280
361
fmt .Print ("!! A few files (index, data_0-3) are in use by Discord while !!\n " )
@@ -284,34 +365,11 @@ func main() {
284
365
fmt .Print ("!! while copying the files over. !!\n " )
285
366
fmt .Print ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n \n " )
286
367
287
- fmt .Print ("Press enter to continue ...\n " )
288
- fmt .Scanln ()
289
-
290
- // Discord client build names
291
- discordBuildName := map [int ]string {
292
- 0 : "Stable" ,
293
- 1 : "PTB" ,
294
- 2 : "Canary" ,
295
- 3 : "Development" ,
296
- }
297
- // Discord client build folder names
298
- discordBuildDir := map [int ]string {
299
- 0 : "discord" ,
300
- 1 : "discordptb" ,
301
- 2 : "discordcanary" ,
302
- 3 : "discorddevelopment" ,
303
- }
304
- // Cache paths for each platform
305
- cachePath := map [string ]string {
306
- "linux" : "%s/.config/%s/Cache/" ,
307
- "darwin" : "%s/Library/Application Support/%s/Cache/" ,
308
- "windows" : "%s\\ AppData\\ Roaming\\ %s\\ Cache\\ " ,
368
+ if opts .Noninteractive == false {
369
+ fmt .Print ("Press enter to continue ...\n " )
370
+ fmt .Scanln ()
309
371
}
310
372
311
- // Initialise a few maps
312
- pathStatus := make (map [int ]bool )
313
- cachedFile := make (map [int ]map [int ]string )
314
-
315
373
fmt .Print ("Checking for existing cache directories ...\n \n " )
316
374
317
375
// Check if directories exist
@@ -420,6 +478,9 @@ func main() {
420
478
fmt .Printf ("[NOTICE] Cannot read client-critial cache while Discord %s is running\n " , discordBuildName [i ])
421
479
fmt .Printf ("[...] Unable to read %d client-critial cache file(s)\n " , unreadableRes )
422
480
unreadableResCount := int64 (len (cachedFile [i ])) - unreadableRes
481
+ if unreadableResCount < 0 {
482
+ unreadableResCount = 0
483
+ }
423
484
fmt .Printf ("[...] Actually copied %d cache files from Discord %s\n " , unreadableResCount , discordBuildName [i ])
424
485
}
425
486
}
0 commit comments