Skip to content

Commit

Permalink
Added registry warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChriZ982 committed Apr 17, 2020
1 parent 9c297d8 commit e3dd7a6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ before_install:
install:
- dep ensure
script:
- go build -o GOG_Galaxy_Start_Menu.exe
- go build -o GOG_Galaxy_Start_Menu.exe ./src/
deploy:
provider: releases
api_key:
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"program": "${workspaceFolder}/src/main.go",
"env": {"CGO_ENABLED":1},
"args": ["-level", "DEBUG", "-layoutWidth", "4", "-tileSize", "2"]
"args": ["-level", "DEBUG", "-layoutWidth", "4", "-groupName", "GOG Galaxy 2.0 Games", "-y"]
}
]
}
9 changes: 7 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,28 @@ This script lets you create Start Menu Tiles of your favourite games in Windows
</table>

## :sparkles: Planned Features
* [ ] Add build pipeline
* [x] Add build pipeline
* [ ] Remember tiles and remove old image files
* [ ] Possibility to choose different icon image source
* [ ] Add custom Start Menu group name setting
* [ ] Test whether registry folder exists
* [x] Add custom Start Menu group name setting
* [x] Test whether registry folder exists

## :hammer_and_wrench: Usage
```
Usage of GOG_Galaxy_Start_Menu.exe:
-database string
Path to GOG Galaxy 2.0 database. (default "C:/ProgramData/GOG.com/Galaxy/storage/galaxy-2.0.db")
-layoutWidth int
Defines the tile count per row in the Start Menu Layout (3 or 4). (default 3)
-level string
Defines log level. (default "INFO")
-startFolder string
Path for game shortcuts and image data. (default "/Appdata/Roaming/Microsoft/Windows/Start Menu/Programs/GOG.com/GameTiles/")
-tileSize int
Size of the individual game tiles (1 or 2). (default 2)
-database string
Path to GOG Galaxy 2.0 database. (default "C:/ProgramData/GOG.com/Galaxy/storage/galaxy-2.0.db")
-groupName string
Name of the Start Menu group.
-layoutWidth int
Defines the tile count per row in the Start Menu Layout (3 or 4). (default 3)
-level string
Defines log level. (default "INFO")
-startFolder string
Path for game shortcuts and image data. (default "/Appdata/Roaming/Microsoft/Windows/Start Menu/Programs/GOG.com/GameTiles/")
-tileSize int
Size of the individual game tiles (1 or 2). (default 2)
-y Always confirm creation of Start Layout.
```

## :earth_africa: Contributing
Expand Down
84 changes: 64 additions & 20 deletions main.go → src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"regexp"
"runtime"
"strings"
"time"

_ "github.com/mattn/go-sqlite3"
"github.com/shiena/ansicolor"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/windows/registry"
)

const sqlTaggedGames = `SELECT UserReleaseTags.releaseKey, WebCacheResources.filename, GamePieces.value FROM UserReleaseTags
Expand All @@ -27,7 +29,7 @@ const partialStartLayoutBegin = `<LayoutModificationTemplate xmlns:defaultlayout
<DefaultLayoutOverride LayoutCustomizationRestrictionType="OnlySpecifiedGroups">
<StartLayoutCollection>
<defaultlayout:StartLayout GroupCellWidth="8">
<start:Group Name="">`
<start:Group Name="%s">`

const startLayoutTile = `
<start:DesktopApplicationTile Size="%[1]dx%[1]d" Column="%[2]d" Row="%[3]d" DesktopApplicationLinkPath="%%APPDATA%%\Microsoft\Windows\Start Menu\Programs\GOG.com\GameTiles\%[4]s.lnk" />`
Expand All @@ -45,22 +47,6 @@ $Shortcut = $WScriptShell.CreateShortcut("%s.lnk")
$Shortcut.TargetPath = "%s.bat"
$Shortcut.Save()`

const powershellApplyStartLayout = `$fileName = "$(Get-Location)\PartialStartLayout.xml"
Export-StartLayout -Path "StartLayoutBackup.xml"
sleep 5
$WindowsUpdateRegKey = "HKCU:\Software\Policies\Microsoft\Windows\Explorer"
if(-not (Test-Path $WindowsUpdateRegKey))
{
New-Item -Path $WindowsUpdateRegKey -Force
}
Set-ItemProperty -Path $WindowsUpdateRegKey -Name StartLayoutFile -Value "$fileName" -Type ExpandString
Set-ItemProperty -Path $WindowsUpdateRegKey -Name LockedStartLayout -Value 1 -Type DWord
Stop-Process -ProcessName explorer
sleep 10
Set-ItemProperty -Path $WindowsUpdateRegKey -Name LockedStartLayout -Value 0 -Type DWord
Stop-Process -ProcessName explorer`

const visualElements = `<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<VisualElements ShowNameOnSquare150x150Logo="on" Square150x150Logo="VisualElements\MediumIcon%[1]s.png" Square70x70Logo="VisualElements\MediumIcon%[1]s.png" ForegroundText="light" BackgroundColor="#5A391B" />
Expand All @@ -73,6 +59,8 @@ var databaseFile = flag.String("database", "C:/ProgramData/GOG.com/Galaxy/storag
var startMenuDir = flag.String("startFolder", "/Appdata/Roaming/Microsoft/Windows/Start Menu/Programs/GOG.com/GameTiles/", "Path for game shortcuts and image data.")
var width = flag.Int("layoutWidth", 3, "Defines the tile count per row in the Start Menu Layout (3 or 4).")
var tileSize = flag.Int("tileSize", 2, "Size of the individual game tiles (1 or 2).")
var yes = flag.Bool("y", false, "Always confirm creation of Start Layout.")
var groupName = flag.String("groupName", "", "Name of the Start Menu group.")

func main() {
flag.Parse()
Expand All @@ -97,6 +85,9 @@ func main() {

games := listGames()
createStartMenu(games)
updateRegistry()

log.Info("Program finished!")
}

func listGames() *map[string]map[string]string {
Expand Down Expand Up @@ -151,7 +142,7 @@ func createStartMenu(games *map[string]map[string]string) {
}

log.Info("Creating Start Menu layout...")
partialStartLayout := partialStartLayoutBegin
partialStartLayout := fmt.Sprintf(partialStartLayoutBegin, *groupName)
tileCount := 0
actualWidth := *width * (3 - *tileSize)
for key, val := range *games {
Expand All @@ -171,10 +162,54 @@ func createStartMenu(games *map[string]map[string]string) {

partialStartLayout += partialStartLayoutEnd
writeFile("PartialStartLayout.xml", partialStartLayout)
}

func updateRegistry() {
log.Info("Updating Start Menu...")
execPowershell(powershellApplyStartLayout)
log.Info("Program finished!")
execPowershell("Export-StartLayout -Path StartLayoutBackup.xml")
key, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Policies\Microsoft\Windows\Explorer`, registry.ALL_ACCESS)
if err != nil {
log.Fatal("Could not create Registry Key. ", err)
}
defer key.Close()
values, err := key.ReadValueNames(0)
if err != nil {
log.Fatal("Could not list Registry values")
}
if find(values, "StartLayoutFile") || find(values, "LockedStartLayout") {
log.Warn("Registry Value 'StartLayoutFile' or 'LockedStartLayout' exists. There might have been a Start Layout previously applied! This would be removed entirely!")
}
if !*yes {
log.Warning("The script will now create registry values to modify the Start Menu. The groups in your Start Menu will probably be reordered. If there was a custom Start Layout .xml file applied before, all tiles will be removed! Use at own risk!\nDo you want to proceed? [yN]")
var proceed string
fmt.Scanln(&proceed)
if proceed != "y" {
log.Info("Script cancelled by user.")
return
}
}
wd, err := os.Getwd()
if err != nil {
log.Fatal("Not able to get working directory. ", err)
}
err1 := key.SetExpandStringValue("StartLayoutFile", wd+"\\PartialStartLayout.xml")
err2 := key.SetDWordValue("LockedStartLayout", 1)
if err1 != nil || err2 != nil {
log.Fatal("Could not set registry value. ", err)
}
execPowershell("Stop-Process -ProcessName explorer")
time.Sleep(5 * time.Second)
err = key.SetDWordValue("LockedStartLayout", 0)
if err != nil {
log.Fatal("Could not set registry value. ", err)
}
execPowershell("Stop-Process -ProcessName explorer")
time.Sleep(3 * time.Second)
err3 := key.DeleteValue("StartLayoutFile")
err4 := key.DeleteValue("LockedStartLayout")
if err3 != nil || err4 != nil {
log.Fatal("Could not delete registry value. ", err)
}
}

func execPowershell(cmdText string, args ...interface{}) {
Expand Down Expand Up @@ -213,3 +248,12 @@ func writeFile(filePath string, contents string) {
}
f.Close()
}

func find(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}

0 comments on commit e3dd7a6

Please sign in to comment.