@@ -3,7 +3,6 @@ package main
3
3
import (
4
4
"bufio"
5
5
"fmt"
6
- "io/ioutil"
7
6
"os"
8
7
"path/filepath"
9
8
"regexp"
@@ -36,6 +35,7 @@ func main() {
36
35
// Log box
37
36
logBox := widget .NewMultiLineEntry ()
38
37
logBox .Disable ()
38
+ logScroll := container .NewVScroll (logBox )
39
39
40
40
// Games list
41
41
gamesList := widget .NewList (
@@ -46,15 +46,18 @@ func main() {
46
46
return len (selectedLibrary .Games )
47
47
},
48
48
func () fyne.CanvasObject {
49
- return container . NewHBox ( widget .NewLabel ("Game" ), widget . NewLabel ( "Auto-update" ) )
49
+ return widget .NewLabel ("Game Name - Update Behavior" )
50
50
},
51
51
func (id widget.ListItemID , item fyne.CanvasObject ) {
52
52
if selectedLibrary == nil {
53
53
return
54
54
}
55
55
game := selectedLibrary .Games [id ]
56
- item .(* fyne.Container ).Objects [0 ].(* widget.Label ).SetText (game .Name )
57
- item .(* fyne.Container ).Objects [1 ].(* widget.Label ).SetText (game .AutoUpdateBehavior )
56
+ updateBehavior := "Auto Update"
57
+ if game .AutoUpdateBehavior == "1" {
58
+ updateBehavior = "Update On Launch"
59
+ }
60
+ item .(* widget.Label ).SetText (fmt .Sprintf ("%s - %s" , game .Name , updateBehavior ))
58
61
},
59
62
)
60
63
@@ -72,6 +75,11 @@ func main() {
72
75
},
73
76
)
74
77
78
+ // Automatically select the first library
79
+ if len (libraries ) > 0 {
80
+ librarySelect .SetSelected (libraries [0 ].Path )
81
+ }
82
+
75
83
// Update behavior selection
76
84
updateBehavior := widget .NewSelect (
77
85
[]string {"0 - Always keep this game updated" , "1 - Only update this game when I launch it" },
@@ -85,7 +93,7 @@ func main() {
85
93
return
86
94
}
87
95
go func () {
88
- updatedGames := updateLibrary (selectedLibrary , updateBehavior .Selected [:1 ], logBox )
96
+ updatedGames := updateLibrary (selectedLibrary , updateBehavior .Selected [:1 ], logBox , logScroll )
89
97
selectedLibrary .Games = updatedGames
90
98
for i , lib := range libraries {
91
99
if lib .Path == selectedLibrary .Path {
@@ -107,15 +115,14 @@ func main() {
107
115
updateBehavior ,
108
116
updateButton ,
109
117
widget .NewLabel ("Operation Log:" ),
110
- container . NewVScroll ( logBox ) ,
118
+ logScroll ,
111
119
)
112
120
113
121
// Set minimum sizes for scrollable areas
114
122
gamesListScroll := content .Objects [3 ].(* container.Scroll )
115
123
gamesListScroll .SetMinSize (fyne .NewSize (500 , 200 ))
116
124
117
- logBoxScroll := content .Objects [8 ].(* container.Scroll )
118
- logBoxScroll .SetMinSize (fyne .NewSize (500 , 100 ))
125
+ logScroll .SetMinSize (fyne .NewSize (500 , 100 ))
119
126
120
127
w .SetContent (content )
121
128
w .Resize (fyne .NewSize (600 , 600 ))
@@ -154,12 +161,17 @@ func detectSteamLibraries() []SteamLibrary {
154
161
}
155
162
156
163
func parseLibraryFoldersVDF (path string ) []string {
157
- libraries := []string {}
164
+ var libraries []string
158
165
file , err := os .Open (path )
159
166
if err != nil {
160
167
return libraries
161
168
}
162
- defer file .Close ()
169
+ defer func (file * os.File ) {
170
+ err := file .Close ()
171
+ if err != nil {
172
+ fmt .Printf (err .Error ())
173
+ }
174
+ }(file )
163
175
164
176
scanner := bufio .NewScanner (file )
165
177
pathRegex := regexp .MustCompile (`^\s*"path"\s*"(.+)"` )
@@ -177,7 +189,7 @@ func parseLibraryFoldersVDF(path string) []string {
177
189
func detectGames (libraryPath string ) []Game {
178
190
var games []Game
179
191
steamappsPath := filepath .Join (libraryPath , "steamapps" )
180
- files , err := ioutil .ReadDir (steamappsPath )
192
+ files , err := os .ReadDir (steamappsPath )
181
193
if err != nil {
182
194
fmt .Println ("Error reading steamapps directory:" , err )
183
195
return games
@@ -198,7 +210,7 @@ func detectGames(libraryPath string) []Game {
198
210
}
199
211
200
212
func parseACF (filePath string ) * Game {
201
- content , err := ioutil .ReadFile (filePath )
213
+ content , err := os .ReadFile (filePath )
202
214
if err != nil {
203
215
fmt .Println ("Error reading ACF file:" , err )
204
216
return nil
@@ -235,7 +247,7 @@ func parseACF(filePath string) *Game {
235
247
return game
236
248
}
237
249
238
- func updateLibrary (lib * SteamLibrary , newBehavior string , logBox * widget.Entry ) []Game {
250
+ func updateLibrary (lib * SteamLibrary , newBehavior string , logBox * widget.Entry , logScroll * container. Scroll ) []Game {
239
251
steamappsPath := filepath .Join (lib .Path , "steamapps" )
240
252
var wg sync.WaitGroup
241
253
updatedGames := make ([]Game , len (lib .Games ))
@@ -248,36 +260,36 @@ func updateLibrary(lib *SteamLibrary, newBehavior string, logBox *widget.Entry)
248
260
// Find the correct appmanifest file
249
261
files , err := filepath .Glob (filepath .Join (steamappsPath , "appmanifest_*.acf" ))
250
262
if err != nil {
251
- logBox . SetText (logBox . Text + fmt .Sprintf ("Error searching for %s: %v\n " , game .Name , err ))
263
+ appendToLog (logBox , logScroll , fmt .Sprintf ("Error searching for %s: %v\n " , game .Name , err ))
252
264
return
253
265
}
254
266
for _ , file := range files {
255
- content , err := ioutil .ReadFile (file )
267
+ content , err := os .ReadFile (file )
256
268
if err != nil {
257
269
continue
258
270
}
259
271
if strings .Contains (string (content ), fmt .Sprintf (`"name" "%s"` , game .Name )) {
260
272
err := updateACF (file , newBehavior )
261
273
if err != nil {
262
- logBox . SetText (logBox . Text + fmt .Sprintf ("Failed to update %s: %v\n " , game .Name , err ))
274
+ appendToLog (logBox , logScroll , fmt .Sprintf ("Failed to update %s: %v\n " , game .Name , err ))
263
275
} else {
264
- logBox . SetText (logBox . Text + fmt .Sprintf ("Successfully updated %s\n " , game .Name ))
276
+ appendToLog (logBox , logScroll , fmt .Sprintf ("Successfully updated %s\n " , game .Name ))
265
277
updatedGames [i ].AutoUpdateBehavior = newBehavior
266
278
}
267
279
return
268
280
}
269
281
}
270
- logBox . SetText (logBox . Text + fmt .Sprintf ("Failed to find appmanifest for %s\n " , game .Name ))
282
+ appendToLog (logBox , logScroll , fmt .Sprintf ("Failed to find appmanifest for %s\n " , game .Name ))
271
283
}(i , game )
272
284
}
273
285
wg .Wait ()
274
- logBox . SetText (logBox . Text + "Update complete.\n " )
286
+ appendToLog (logBox , logScroll , "Update complete.\n " )
275
287
276
288
return updatedGames
277
289
}
278
290
279
291
func updateACF (filePath , newBehavior string ) error {
280
- content , err := ioutil .ReadFile (filePath )
292
+ content , err := os .ReadFile (filePath )
281
293
if err != nil {
282
294
return err
283
295
}
@@ -310,7 +322,7 @@ func updateACF(filePath, newBehavior string) error {
310
322
"}" )
311
323
}
312
324
313
- return ioutil .WriteFile (filePath , []byte (strings .Join (newLines , "\n " )), 0644 )
325
+ return os .WriteFile (filePath , []byte (strings .Join (newLines , "\n " )), 0644 )
314
326
}
315
327
316
328
func getLibraryPaths (libraries []SteamLibrary ) []string {
@@ -320,3 +332,9 @@ func getLibraryPaths(libraries []SteamLibrary) []string {
320
332
}
321
333
return paths
322
334
}
335
+
336
+ func appendToLog (logBox * widget.Entry , logScroll * container.Scroll , message string ) {
337
+ logBox .SetText (logBox .Text + message )
338
+ logScroll .ScrollToBottom ()
339
+ logScroll .Refresh ()
340
+ }
0 commit comments