<commit_before>package appdirs

import (
	"path/filepath"
	"strings"
	"syscall"
	"unsafe"
)

var (
	shell32, _        = syscall.LoadLibrary("shell32.dll")
	getFolderPathW, _ = syscall.GetProcAddress(shell32, "SHGetFolderPathW")
)

type Csidl uint

const (
	APPDATA        Csidl = 26
	COMMON_APPDATA       = 35
	LOCAL_APPDATA        = 28
)

func (app *App) UserData() string {
	var author string
	if author = app.Author; author == "" {
		author = app.Name
	}

	var csidl Csidl
	if app.Roaming {
		csidl = APPDATA
	} else {
		csidl = LOCAL_APPDATA
	}

	path, err := GetFolderPath(csidl)

	if err != nil {
		return ""
	}

	if path, err = filepath.Abs(path); err != nil {
		return ""
	}

	if app.Name != "" {
		return filepath.Join(path, author, app.Name)
	} else {
		return path
	}
}

func GetFolderPath(csidl_const Csidl) (string, error) {
	var buf = strings.Repeat("0", 1024)
	cbuf, err := syscall.UTF16FromString(buf)
	if err != nil {
		return "", err
	}

	ret, _, callErr := syscall.Syscall6(
		uintptr(getFolderPathW),
		5,                    // The amount of arguments we have
		0,                    // Reserved argument, does nothing
		uintptr(csidl_const), // CSIDL value identifier
		0,                    // Access token, almost always 0
		0,                    // Flag to specify the path to be returned
		// null-terminated string to put the output in<commit_msg>Added SiteDir method to *App<commit_after>package appdirs

import (
	"path/filepath"
	"strings"
	"syscall"
	"unsafe"
)

var (
	shell32, _        = syscall.LoadLibrary("shell32.dll")
	getFolderPathW, _ = syscall.GetProcAddress(shell32, "SHGetFolderPathW")
)

type Csidl uint

const (
	APPDATA        Csidl = 26
	COMMON_APPDATA       = 35
	LOCAL_APPDATA        = 28
)

func (app *App) UserData() string {
	var author string
	if author = app.Author; author == "" {
		author = app.Name
	}

	var csidl Csidl
	if app.Roaming {
		csidl = APPDATA
	} else {
		csidl = LOCAL_APPDATA
	}

	path, err := GetFolderPath(csidl)

	if err != nil {
		return ""
	}

	if path, err = filepath.Abs(path); err != nil {
		return ""
	}

	if app.Name != "" {
		return filepath.Join(path, author, app.Name)
	} else {
		return path
	}
}

func (app *App) SiteData() (path string) {
	path, err := GetFolderPath(COMMON_APPDATA)

	if err != nil {
		return ""
	}

	if path, err = filepath.Abs(path); err != nil {
		return ""
	}

	author := app.Author

	if author == "" {
		author = app.Name
	}

	if app.Name != "" {
		return filepath.Join(path, author, app.Name)
	} else {
		return path
	}
}

func GetFolderPath(csidl_const Csidl) (string, error) {
	var buf = strings.Repeat("0", 1024)
	cbuf, err := syscall.UTF16FromString(buf)
	if err != nil {
		return "", err
	}

	ret, _, callErr := syscall.Syscall6(
		uintptr(getFolderPathW),
		5,                    // The amount of arguments we have
		0,                    // Reserved argument, does nothing
		uintptr(csidl_const), // CSIDL value identifier
		0,                    // Access token, almost always 0
		0,                    // Flag to specify the path to be returned
		// null-terminated string to put the output in
{'fraction_non_alphanumeric': 0.11989713918354226, 'fraction_numerical': 0.016072002571520413, 'mean_word_length': 2.5647193585337917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3696445', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1105, 'n_words': 298}