Skip to content

Commit 3425521

Browse files
committed
Add flatpak support under a flag
1 parent 0a11505 commit 3425521

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Discord Cache Dump is a tool that gathers the cache of all known Electron Discor
2222
## Features
2323

2424
- Detection of known Discord build types (can do multiple in a single run)
25+
- Flatpak support using `--flatpak` (or `-f`) flag (i.e. `./dcd --flatpak`)
2526
- Discloses count of amount of files it is unable to gather at the time for that particular build
2627
- Supports Windows, GNU/Linux, and macOS
2728
- Checks storage available where the program is being ran before copying

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ require (
88
github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285
99
)
1010

11-
require golang.org/x/sys v0.1.0 // indirect
11+
require (
12+
golang.org/x/sys v0.1.0 // indirect
13+
golang.org/x/text v0.16.0 // indirect
14+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285/go.m
77
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
88
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
99
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10+
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
11+
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=

main.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
const (
19-
softVersion = "1.2.4"
19+
softVersion = "1.3.0"
2020
dumpDir = "dump"
2121
)
2222

@@ -75,6 +75,7 @@ func main() {
7575

7676
var opts struct {
7777
Build string `short:"b" long:"build" description:"Select build type: stable, ptb, canary, development"`
78+
Flatpak bool `short:"f" long:"flatpak" description:"Target flatpak builds (Linux only)"`
7879
Noninteractive bool `short:"n" long:"noninteractive" description:"Non-interactive -- no 'enter' key required"`
7980
}
8081

@@ -189,11 +190,20 @@ func main() {
189190
fmt.Scanln()
190191
}
191192

193+
flatpakMode := opts.Flatpak && platform == "linux"
194+
if flatpakMode {
195+
fmt.Print("Flatpak mode\n")
196+
}
197+
192198
fmt.Print("Checking for existing cache directories ...\n\n")
193199

194200
// Check if directories exist
195201
for i := 0; i < len(discordBuildDir); i++ {
196-
filePath := fmt.Sprintf(cachePath[platform], homePath, discordBuildDir[i])
202+
filePathRaw := cachePath[platform]
203+
if flatpakMode {
204+
filePathRaw = DCDUtils.FlatpakPath(discordBuildDir[i])
205+
}
206+
filePath := fmt.Sprintf(filePathRaw, homePath, discordBuildDir[i])
197207
if _, err := os.Stat(filePath); !os.IsNotExist(err) {
198208
fmt.Printf("Found: Discord %s\n", discordBuildName[i])
199209
pathStatus[i] = true
@@ -205,7 +215,11 @@ func main() {
205215
// Check if the directories are empty and store names of cached files
206216
for i := 0; i < len(discordBuildDir); i++ {
207217
if pathStatus[i] {
208-
filePath := fmt.Sprintf(cachePath[platform], homePath, discordBuildDir[i])
218+
filePathRaw := cachePath[platform]
219+
if flatpakMode {
220+
filePathRaw = DCDUtils.FlatpakPath(discordBuildDir[i])
221+
}
222+
filePath := fmt.Sprintf(filePathRaw, homePath, discordBuildDir[i])
209223
cacheListing, err := ioutil.ReadDir(filePath)
210224
if err != nil {
211225
fmt.Printf("[ERROR] Unable to read directory for Discord %s%s", discordBuildName[i], DCDUtils.ExitNewLine())
@@ -216,7 +230,7 @@ func main() {
216230
cachedFile[i] = make(map[int]string)
217231
for k, v := range cacheListing {
218232
cachedFile[i][k] = v.Name()
219-
overallSize = DCDUtils.SizeStore(filePath + v.Name(), overallSize)
233+
overallSize = DCDUtils.SizeStore(filePath+v.Name(), overallSize)
220234
}
221235
fmt.Printf("Discord %s :: found %d cached files\n", discordBuildName[i], len(cacheListing))
222236
} else {
@@ -286,7 +300,11 @@ func main() {
286300
fmt.Printf("Copying %d files from Discord %s ...\n", len(cachedFile[i]), discordBuildName[i])
287301
for it := 0; it < len(cachedFile[i]); it++ {
288302
// Build the paths to use during the copy operation
289-
fromPath := fmt.Sprintf(cachePath[platform], homePath, discordBuildDir[i])
303+
filePathRaw := cachePath[platform]
304+
if flatpakMode {
305+
filePathRaw = DCDUtils.FlatpakPath(discordBuildDir[i])
306+
}
307+
fromPath := fmt.Sprintf(filePathRaw, homePath, discordBuildDir[i])
290308
toPath := dumpDir + "/" + timeDateStamp + "/" + discordBuildName[i] + "/" + cachedFile[i][it]
291309
// Copying the files one-by-one
292310
unreadableRes = DCDUtils.CopyFile(fromPath+cachedFile[i][it], toPath, sudoerUID, unreadableRes)

utils/process.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,38 @@ import (
88
"regexp"
99
"runtime"
1010
"strconv"
11+
"strings"
12+
13+
"golang.org/x/text/cases"
14+
"golang.org/x/text/language"
1115
)
1216

17+
// Formulate the end of the flatpak package name to then use as a normal path
18+
func FlatpakPath(buildType string) string {
19+
resultingBuildSegment := ""
20+
splitBuildName := strings.Split(buildType, "discord")
21+
if len(splitBuildName) > 1 {
22+
if splitBuildName[1] != "" {
23+
resultingBuildSegment = strings.Join([]string{"discord", splitBuildName[1]}, " ")
24+
} else {
25+
resultingBuildSegment = buildType
26+
}
27+
} else {
28+
resultingBuildSegment = buildType
29+
}
30+
31+
titleCaser := cases.Title(language.English)
32+
casedBuildName := titleCaser.String(resultingBuildSegment)
33+
34+
packageNameSuffix := strings.Replace(casedBuildName, " ", "", -1)
35+
36+
path := "%s/.var/app/com.discordapp.%s/config/%s/Cache/Cache_Data/"
37+
path = fmt.Sprintf(path, "%s", packageNameSuffix, "%s")
38+
39+
return path
40+
}
41+
42+
1343
// Extract cache files (for GNU/Linux and macOS)
1444
func FileExtractor(contents []byte) []byte {
1545
var magicNumber string

0 commit comments

Comments
 (0)