mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-14 01:04:14 +00:00
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
// Copyright (C) 2014 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
// +build windows
|
|
|
|
package osutil
|
|
|
|
import "syscall"
|
|
|
|
func HideFile(path string) error {
|
|
p, err := syscall.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
attrs, err := syscall.GetFileAttributes(p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
attrs |= syscall.FILE_ATTRIBUTE_HIDDEN
|
|
return syscall.SetFileAttributes(p, attrs)
|
|
}
|
|
|
|
func ShowFile(path string) error {
|
|
p, err := syscall.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
attrs, err := syscall.GetFileAttributes(p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
attrs &^= syscall.FILE_ATTRIBUTE_HIDDEN
|
|
return syscall.SetFileAttributes(p, attrs)
|
|
}
|
|
|
|
func HideConsole() {
|
|
getConsoleWindow := syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow")
|
|
showWindow := syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow")
|
|
if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
|
|
hwnd, _, _ := getConsoleWindow.Call()
|
|
if hwnd != 0 {
|
|
showWindow.Call(hwnd, 0)
|
|
}
|
|
}
|
|
}
|