Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Add windows tools
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Mar 6, 2020
1 parent ddb14de commit cdc5ceb
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
Empty file.
99 changes: 99 additions & 0 deletions guiscrcpy/platform/windows_tools/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python
"""
Create desktop shortcuts for Windows
"""
from __future__ import print_function
import os
import sys
import time
from collections import namedtuple
UserFolders = namedtuple("UserFolders", ("home", "desktop", "startmenu"))
import win32com.client
from win32com.shell import shell, shellcon

scut_ext = 'lnk'
ico_ext = 'ico'

def get_conda_active_env():
'''Return name of active conda environment or empty string'''
conda_env = None
try:
conda_env = os.environ['CONDA_DEFAULT_ENV']
except KeyError:
print("No conda env active, defaulting to base")
conda_env = ""
return conda_env

# batch file to activate the environment
# for Anaconda Python before running command.
conda_env = get_conda_active_env()
ENVRUNNER = """
@ECHO OFF
call %~dp0%activate {0}
echo # run in conda environment "%CONDA_DEFAULT_ENV%":
echo # %*
%*
""".format(conda_env)

_WSHELL = win32com.client.Dispatch("Wscript.Shell")


# Windows Special Folders
# see: https://docs.microsoft.com/en-us/windows/win32/shell/csidl

def get_homedir():
'''Return home directory:
note that we return CSIDL_PROFILE, not
CSIDL_APPDATA, CSIDL_LOCAL_APPDATA, or CSIDL_COMMON_APPDATA
'''
return shell.SHGetFolderPath(0, shellcon.CSIDL_PROFILE, None, 0)


def get_desktop():
'''Return user Desktop folder'''
return shell.SHGetFolderPath(0, shellcon.CSIDL_DESKTOP, None, 0)


def get_startmenu():
'''Return user Start Menu Programs folder
note that we return CSIDL_PROGRAMS not CSIDL_COMMON_PROGRAMS
'''
return shell.SHGetFolderPath(0, shellcon.CSIDL_PROGRAMS, None, 0)


def get_folders():
"""get user-specific folders
Returns:
-------
Named tuple with fields 'home', 'desktop', 'startmenu'
Example:
-------
>>> from pyshortcuts import get_folders
>>> folders = get_folders()
>>> print("Home, Desktop, StartMenu ",
... folders.home, folders.desktop, folders.startmenu)
"""
return UserFolders(get_homedir(), get_desktop(), get_startmenu())

def make_shortcut():
userfolders = get_folders()

full_script = 'guiscrcpy'
desktop, startmenu = True, True
for (create, folder) in ((desktop,userfolders.desktop),
(startmenu, userfolders.startmenu)):

if not os.path.exists(folder):
os.makedirs(folder)
dest = os.path.join(folder, "guiscrcpy.lnk")

wscript = _WSHELL.CreateShortCut(dest)
wscript.Targetpath = 'guiscrcpy.exe'
wscript.WorkingDirectory = userfolders.home
wscript.WindowStyle = 0
wscript.Description = "An Open Source Android Screen Mirroring System"
wscript.IconLocation = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
'ui', 'icons', 'guiscrcpy_logo_SRj_icon.ico')
wscript.save()

return True

0 comments on commit cdc5ceb

Please sign in to comment.