9
9
"log/slog"
10
10
"os"
11
11
"path/filepath"
12
+ "regexp"
12
13
"runtime"
13
14
"strings"
14
15
"time"
@@ -47,7 +48,9 @@ func addDefaultFactoryGameLog(writer *zip.Writer) error {
47
48
if err != nil {
48
49
return fmt .Errorf ("failed to get user cache dir: %w" , err )
49
50
}
50
- err = utils .AddFileToZip (writer , filepath .Join (cacheDir , "FactoryGame" , "Saved" , "Logs" , "FactoryGame.log" ), "FactoryGame.log" )
51
+ defaultLogPath := filepath .Join (cacheDir , "FactoryGame" , "Saved" , "Logs" , "FactoryGame.log" )
52
+ // Default log will always be on the local disk, if it exists
53
+ bytes , err := os .ReadFile (defaultLogPath )
51
54
if err != nil {
52
55
if errors .Is (err , os .ErrNotExist ) {
53
56
if runtime .GOOS != "windows" {
@@ -57,59 +60,80 @@ func addDefaultFactoryGameLog(writer *zip.Writer) error {
57
60
}
58
61
return fmt .Errorf ("log does not exist" )
59
62
}
60
- return fmt .Errorf ("failed to add FactoryGame.log to zip: %w" , err )
63
+ return fmt .Errorf ("failed to read default FactoryGame.log: %w" , err )
64
+ }
65
+ err = addLogFromBytes (writer , bytes , "FactoryGame.log" )
66
+ if err != nil {
67
+ return fmt .Errorf ("failed to add default FactoryGame.log to zip: %w" , err )
68
+ }
69
+ return nil
70
+ }
71
+
72
+ func redactLogBytes (bytes []byte ) []byte {
73
+ // Prevent leaking of Steam/Epic friend nicknames in submitted logs
74
+ re := regexp .MustCompile (`(Added friend with nickname ').*(' on online context)` )
75
+ return re .ReplaceAll (bytes , []byte ("${1}REDACTED${2}" ))
76
+ }
77
+
78
+ func addLogFromBytes (writer * zip.Writer , bytes []byte , zipFileName string ) error {
79
+ redactedBytes := redactLogBytes (bytes )
80
+
81
+ logFile , err := writer .Create (zipFileName )
82
+ if err != nil {
83
+ return fmt .Errorf ("failed to create log file in zip: %w" , err )
84
+ }
85
+
86
+ _ , err = logFile .Write (redactedBytes )
87
+ if err != nil {
88
+ return fmt .Errorf ("failed to write log file to zip: %w" , err )
61
89
}
62
90
return nil
63
91
}
64
92
65
93
func addInstallFactoryGameLog (writer * zip.Writer , install * common.Installation ) error {
66
94
logPath := filepath .Join (install .SavedPath , "Logs" , "FactoryGame.log" )
95
+ // Install-specific logs could be on remote disks
67
96
d , err := ficsitcli .FicsitCLI .GetInstallation (install .Path ).GetDisk ()
68
97
if err != nil {
69
98
return fmt .Errorf ("failed to get disk for installation: %w" , err )
70
99
}
100
+
71
101
logExists , err := d .Exists (logPath )
72
102
if err != nil {
73
103
return fmt .Errorf ("failed to check if log exists: %w" , err )
74
104
}
75
105
if ! logExists {
76
106
return fmt .Errorf ("log does not exist" )
77
107
}
108
+
78
109
bytes , err := d .Read (logPath )
79
110
if err != nil {
80
111
return fmt .Errorf ("failed to read log file: %w" , err )
81
112
}
82
- logFile , err := writer .Create (getLogNameForInstall (install ))
83
- if err != nil {
84
- return fmt .Errorf ("failed to create log file in zip: %w" , err )
85
- }
86
- _ , err = logFile .Write (bytes )
87
- if err != nil {
88
- return fmt .Errorf ("failed to write log file to zip: %w" , err )
89
- }
90
- return nil
113
+ return addLogFromBytes (writer , bytes , getLogNameForInstall (install ))
91
114
}
92
115
93
116
func addFactoryGameLogs (writer * zip.Writer ) {
94
117
err := addDefaultFactoryGameLog (writer )
95
118
if err != nil {
96
119
slog .Warn ("failed to add default FactoryGame.log to debuginfo zip" , slog .Any ("error" , err ))
97
120
}
98
- for _ , meta := range ficsitcli .FicsitCLI .GetInstallationsMetadata () {
99
- if meta .Info == nil {
121
+ for _ , installMeta := range ficsitcli .FicsitCLI .GetInstallationsMetadata () {
122
+ if installMeta .Info == nil {
100
123
continue
101
124
}
102
125
103
- err := addInstallFactoryGameLog (writer , meta .Info )
126
+ err := addInstallFactoryGameLog (writer , installMeta .Info )
104
127
if err != nil {
105
- slog .Warn ("failed to add FactoryGame.log to debuginfo zip" , slog .String ("path" , meta .Info .Path ), slog .Any ("error" , err ))
128
+ slog .Warn ("failed to add FactoryGame.log to debuginfo zip" , slog .String ("path" , installMeta .Info .Path ), slog .Any ("error" , err ))
106
129
}
107
130
}
108
131
}
109
132
110
133
func getLogNameForInstall (install * common.Installation ) string {
111
134
hash := sha256 .Sum256 ([]byte (install .Path ))
112
- return fmt .Sprintf ("FactoryGame_%s.log" , hex .EncodeToString (hash [:])[:8 ])
135
+ first8 := hex .EncodeToString (hash [:])[:8 ]
136
+ return fmt .Sprintf ("FactoryGame_%s_%s_%s_%s.log" , first8 , install .Location , install .Branch , install .Type )
113
137
}
114
138
115
139
func addMetadata (writer * zip.Writer ) error {
0 commit comments