<commit_before>// SPDX-FileCopyrightText: © 2014-2022 <NAME>
// SPDX-License-Identifier: MIT

//go:build windows
// +build windows

package vmwpatch

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
	"syscall"
	"time"

	"golang.org/x/sys/windows"
	"golang.org/x/sys/windows/registry"
	"golang.org/x/sys/windows/svc"
	"golang.org/x/sys/windows/svc/mgr"
)

var manager *mgr.Mgr

func IsAdmin() bool {
	_, err := os.Open("\\\\.\\PHYSICALDRIVE0")
	if err != nil {
		exe, _ := os.Executable()
		cwd, _ := os.Getwd()

		verbPtr, _ := syscall.UTF16PtrFromString("runas")
		exePtr, _ := syscall.UTF16PtrFromString(exe)
		cwdPtr, _ := syscall.UTF16PtrFromString(cwd)
		argPtr, _ := syscall.UTF16PtrFromString(strings.Join(os.Args[1:], " "))

		err := windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, 1)
		if err != nil {
			fmt.Println(err)
		}
		os.Exit(1)
	}
	return true
}

func VMWStart(v *VMwareInfo) {
	fmt.Println()
	fmt.Println("Starting VMware services and tasks...")
	svcStart(v.AuthD)
	svcStart(v.HostD)
	svcStart(v.USBD)
	err := manager.Disconnect()
	if err != nil {
		fmt.Println("Disconnect from SCM failed")
		// Not stopping the process over this one
	}
	taskStart(filepath.Join(v.InstallDir, v.Tray))
}

func VMWStop(v *VMwareInfo) {
	fmt.Println()
	fmt.Println("Stopping VMware services and tasks...")

	var err error
	manager, err = mgr.Connect()
	if err != nil {
		panic("SCM connection failed")
	}

	svcStop(v.AuthD)
	svcStop(v.HostD)
	svcStop(v.USBD)
	taskStop(v.ShellExt) // No Need to re-exec this, it's part of a registered shell extension
	taskStop(v.Tray)
}

func VMWInfo() *VMwareInfo {<commit_msg>Windows: Fix service start/stop dependency chain<commit_after>// SPDX-FileCopyrightText: © 2014-2022 <NAME>
// SPDX-License-Identifier: MIT

//go:build windows
// +build windows

package vmwpatch

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
	"syscall"
	"time"

	"golang.org/x/sys/windows"
	"golang.org/x/sys/windows/registry"
	"golang.org/x/sys/windows/svc"
	"golang.org/x/sys/windows/svc/mgr"
)

var manager *mgr.Mgr

func IsAdmin() bool {
	_, err := os.Open("\\\\.\\PHYSICALDRIVE0")
	if err != nil {
		exe, _ := os.Executable()
		cwd, _ := os.Getwd()

		verbPtr, _ := syscall.UTF16PtrFromString("runas")
		exePtr, _ := syscall.UTF16PtrFromString(exe)
		cwdPtr, _ := syscall.UTF16PtrFromString(cwd)
		argPtr, _ := syscall.UTF16PtrFromString(strings.Join(os.Args[1:], " "))

		err := windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, 1)
		if err != nil {
			fmt.Println(err)
		}
		os.Exit(1)
	}
	return true
}

func VMWStart(v *VMwareInfo) {
	fmt.Println()
	fmt.Println("Starting VMware services and tasks...")
	svcStart(v.AuthD)
	svcStart(v.HostD)
	svcStart(v.USBD)
	err := manager.Disconnect()
	if err != nil {
		fmt.Println("Disconnect from SCM failed")
		// Not stopping the process over this one
	}
	taskStart(filepath.Join(v.InstallDir, v.Tray))
}

func VMWStop(v *VMwareInfo) {
	fmt.Println()
	fmt.Println("Stopping VMware services and tasks...")

	var err error
	manager, err = mgr.Connect()
	if err != nil {
		panic("SCM connection failed")
	}

	svcStop(v.USBD)
	svcStop(v.HostD)
	svcStop(v.AuthD)
	taskStop(v.ShellExt) // No Need to re-exec this, it's part of a registered shell extension
	taskStop(v.Tray)
}

func VMWInfo() *VMwareInfo {
{'fraction_non_alphanumeric': 0.15971179825878115, 'fraction_numerical': 0.012608826178324827, 'mean_word_length': 3.878477306002928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6925017', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1330, 'n_words': 273}