-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.go
120 lines (112 loc) · 3.71 KB
/
setup.go
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
package main
import (
"fmt"
"os"
"runtime"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/theme"
)
func checkDataFolder(dataFolder string) error {
// Ensure data folder exists
if _, err := os.Stat(dataFolder); os.IsNotExist(err) {
fmt.Println("Data folder not found. Creating...")
if mkDirErr := os.Mkdir(dataFolder, 0755); mkDirErr != nil {
return fmt.Errorf("Error creating data folder: %v", mkDirErr)
}
}
return nil
}
func checkDatabaseFile(jsonFilePath string, jsonURL string, updateFlag bool, window ...fyne.Window) error {
// Check if JSON file exists
if _, err := os.Stat(jsonFilePath); os.IsNotExist(err) {
// Prompt for download if JSON file doesn't exist
if guiEnabled {
if len(window) != 1 {
output1 := canvas.NewText("ERROR: Your local developer did not use the a function correctly!", theme.ErrorColor())
output2 := canvas.NewText("Please open a GitHub issue and show them this output", theme.ErrorColor())
outputContainer.Add(output1)
outputContainer.Add(output2)
}
guiShowDownloadConfirmation(window[0], jsonFilePath, jsonURL)
} else {
if cliPromptForDownload(jsonURL) {
err := loadJSONData(jsonFilePath, "Xbox-Preservation-Project", "Pinecone", "data/id_database.json", &titles, true)
if err != nil {
return fmt.Errorf("error downloading data: %v ", err)
}
} else {
return fmt.Errorf("download aborted by user")
}
}
} else if updateFlag {
// Handle manual update
err := loadJSONData(jsonFilePath, "Xbox-Preservation-Project", "Pinecone", jsonFilePath, &titles, true)
if err != nil {
return fmt.Errorf("error updating data: %v", err)
}
} else {
// Load existing JSON data
err := loadJSONData(jsonFilePath, "Xbox-Preservation-Project", "Pinecone", jsonFilePath, &titles, false)
if err != nil {
return fmt.Errorf("error loading data: %v", err)
}
if guiEnabled {
guiScanDump()
}
}
return nil
}
func checkDumpFolder(dumpLocation string) error {
if dumpLocation != "dump" {
if _, err := os.Stat(dumpLocation); os.IsNotExist(err) {
return fmt.Errorf("Directory does not exist, exiting...")
}
} else {
if _, err := os.Stat(dumpLocation); os.IsNotExist(err) {
fmt.Println("Default dump folder not found. Creating...")
if mkDirErr := os.Mkdir(dumpLocation, 0755); mkDirErr != nil {
return fmt.Errorf("Error creating dump folder: %v", mkDirErr)
}
return fmt.Errorf("Please place TDATA folder in the \"dump\" folder")
}
}
return nil
}
func checkParsingSettings() error {
if titleIDFlag != "" {
// if the titleID flag is set, print stats for that title
printStats(titleIDFlag, false)
} else if summarizeFlag {
// if the summarize flag is set, print stats for all titles
printStats("", true)
} else if fatxplorer {
if runtime.GOOS == "windows" {
if _, err := os.Stat(`X:\`); os.IsNotExist(err) {
return fmt.Errorf(`FatXplorer's X: drive not found`)
} else {
fmt.Println("Checking for Content...")
fmt.Println("====================================================================================================")
err := checkForContent("X:\\TDATA")
if err != nil {
return err
}
}
} else {
return fmt.Errorf("FatXplorer mode is only available on Windows.")
}
} else {
// If no flag is set, proceed normally
// Check if TDATA folder exists
if _, err := os.Stat(dumpLocation + "/TDATA"); os.IsNotExist(err) {
return fmt.Errorf("TDATA folder not found. Please place TDATA folder in the dump folder.")
}
fmt.Println("Checking for Content...")
fmt.Println("====================================================================================================")
err := checkForContent(dumpLocation + "/TDATA")
if err != nil {
return err
}
}
return nil
}