Jacalz / rymdport

Cross-platform application for easy encrypted file, folder, and text sharing between devices.
https://rymdport.github.io/
GNU General Public License v3.0
1.08k stars 53 forks source link

Pick up non-standard Windows Downloads path #118

Closed stdedos closed 1 year ago

stdedos commented 1 year ago

Checklist

Is your feature request related to a problem?

User might have a non-standard Downloads path (i.e., not %USERPROFILE%\Downloads)

Describe the solution you'd like to see.

package main

import (
    "fmt"
    "golang.org/x/sys/windows/registry"
)

func getDownloadsPath() (string, error) {
    k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders`, registry.QUERY_VALUE)
    if err != nil {
        return "", err
    }
    defer k.Close()

    downloads, _, err := k.GetStringValue("{374DE290-123F-4565-9164-39C4925E467B}")
    if err != nil {
        return "", err
    }

    return downloads, nil
}

func main() {
    path, err := getDownloadsPath()
    if err != nil {
        fmt.Println("Failed to get the Downloads path:", err)
        return
    }

    fmt.Println("Downloads path:", path)
}

untested

Jacalz commented 1 year ago

Thanks for opening this issue. I have thought a bit about this and I think I'll have to close this unfortunately. I'm sorry.

Rymdport is a cross-platform application and as such I really want to include as little platform specific code as possible. Given that manually setting the download path is a few clicks away in the settings I'm not sure maintaining platform specific code for this is worth it for me. My access to Windows is sporadic at best and the less that can break between releases the better.

Messing around in the registry also seems kind of dangerous and a bit like magic; especially for someone not well versed in the quirks of Windows :/