13 Commits
msys ... cygwin

Author SHA1 Message Date
David Macek
af68abc9b7 WIP: Add support for Cygwin 2015-12-31 20:15:36 +01:00
David Macek
f91905f6bb WIP: new icons 2015-11-15 17:48:27 +01:00
David Macek
58b5c72ead Add .ini files to backup field of PKGBUILD; Enable expansion of .ini files contents; Add a clean PATH template 2015-11-09 23:46:10 +01:00
David Macek
1a1c5866e0 Fixed indentation 2015-11-04 12:15:25 +01:00
David Macek
a05668dffc Fixed bad value of "Start in" field after pinning; plus various fixed:
- version information consolidated into version.h
- removed strip from Makefile
- updated PKGBUILD
- fixed minor things in launcher.c
- added header guards
2015-11-04 12:11:00 +01:00
David Macek
551bb174b0 Fix MSYSTEM variable detection 2015-10-29 18:09:58 +01:00
David Macek
afa868fd7b Add PKGBUILD 2015-10-28 23:35:42 +01:00
David Macek
619f3830af Set CHERE_INVOKING and MSYSCON 2015-10-28 23:17:14 +01:00
David Macek
174fc35707 Bump version to 0.2 2015-10-28 23:00:55 +01:00
David Macek
292186be44 Refactored path handling; environment is now read from a file 2015-10-28 23:00:42 +01:00
David Macek
2c0e3b8e0c Allow passing arguments in order to launch a command 2015-10-28 22:00:55 +01:00
David Macek
ee4a2d0fe9 Switch to C11; refactor error reporting; switch to dynamic buffer allocation 2015-10-28 21:19:26 +01:00
David Macek
6a011ed295 Switch to unicode; make launcher compatible with new mintty 2015-10-28 20:49:37 +01:00
14 changed files with 272 additions and 167 deletions

10
.gitignore vendored
View File

@@ -1,6 +1,16 @@
/mingw32.exe
/mingw32.res
/mingw32.ini
/mingw64.exe
/mingw64.res
/mingw64.ini
/msys2.exe
/msys2.res
/msys2.ini
/cygwin.exe
/cygwin.res
/cygwin.ini
/pkg/
/src/
/*.pkg.tar.xz
/*.pkg.tar.xz.sig

View File

@@ -1,19 +1,39 @@
all: msys2.exe mingw32.exe mingw64.exe
PREFIX=
msys2: msys2.exe msys2.ini mingw32.exe mingw32.ini mingw64.exe mingw64.ini
cygwin: cygwin.exe cygwin.ini
all: msys2 cygwin
.PHONY: all msys2 cygwin
msys2.ini: launcher.ini
cp -f $^ $@
echo MSYSTEM=MSYS>> $@
msys2.res: launcher.rc msys2.ico
windres -O COFF -o $@ $< -DMSYSTEM=MSYS -DICONFILE=msys2.ico
$(PREFIX)windres -O COFF -o $@ $< -DPRODUCT=MSYS2 -DMSYSTEM=MSYS -DICONFILE=msys2.ico
msys2.exe: launcher.c msys2.res
gcc -Wall -Wextra -static -mwindows -o $@ $^ -luuid -lshlwapi -lpsapi -DMSYSTEM=MSYS
strip $@
$(PREFIX)gcc -std=c11 -Wall -Wextra -Werror -static -municode -mwindows -o $@ $^ -DPRODUCT=MSYS2 -DSHELLPATH='usr\\bin\\mintty.exe'
mingw32.ini: launcher.ini
cp -f $^ $@
echo MSYSTEM=MINGW32>> $@
mingw32.res: launcher.rc mingw32.ico
windres -O COFF -o $@ $< -DMSYSTEM=MINGW32 -DICONFILE=mingw32.ico
$(PREFIX)windres -O COFF -o $@ $< -DPRODUCT=MSYS2 -DMSYSTEM=MINGW32 -DICONFILE=mingw32.ico
mingw32.exe: launcher.c mingw32.res
gcc -Wall -Wextra -static -mwindows -o $@ $^ -luuid -lshlwapi -lpsapi -DMSYSTEM=MINGW32
strip $@
$(PREFIX)gcc -std=c11 -Wall -Wextra -Werror -static -municode -mwindows -o $@ $^ -DPRODUCT=MSYS2 -DSHELLPATH='usr\\bin\\mintty.exe'
mingw64.ini: launcher.ini
cp -f $^ $@
echo MSYSTEM=MINGW64>> $@
mingw64.res: launcher.rc mingw64.ico
windres -O COFF -o $@ $< -DMSYSTEM=MINGW64 -DICONFILE=mingw64.ico
$(PREFIX)windres -O COFF -o $@ $< -DPRODUCT=MSYS2 -DMSYSTEM=MINGW64 -DICONFILE=mingw64.ico
mingw64.exe: launcher.c mingw64.res
gcc -Wall -Wextra -static -mwindows -o $@ $^ -luuid -lshlwapi -lpsapi -DMSYSTEM=MINGW64
strip $@
$(PREFIX)gcc -std=c11 -Wall -Wextra -Werror -static -municode -mwindows -o $@ $^ -DPRODUCT=MSYS2 -DSHELLPATH='usr\\bin\\mintty.exe'
cygwin.ini: launcher.ini
cp -f $^ $@
echo MSYSTEM=CYGWIN>> $@
cygwin.res: launcher.rc cygwin.ico
$(PREFIX)windres -O COFF -o $@ $< -DPRODUCT=Cygwin -DMSYSTEM=CYGWIN -DICONFILE=cygwin.ico
cygwin.exe: launcher.c cygwin.res
$(PREFIX)gcc -std=c11 -Wall -Wextra -Werror -static -municode -mwindows -o $@ $^ -DPRODUCT=Cygwin -DSHELLPATH='bin\\mintty.exe'

36
PKGBUILD Normal file
View File

@@ -0,0 +1,36 @@
_realname="msys2-launcher"
pkgname=("${_realname}-git")
pkgver=0.3.17.1a1c586
pkgrel=1
pkgdesc="Helper for launching MSYS2 shells"
arch=('x86_64' 'i686')
license=('MIT')
backup=({mingw32,mingw64,msys2}.ini)
provides=("${_realname}")
conflicts=("${_realname}")
depends=("mintty>=2.2.1")
makedepends=('mingw-w64-cross-gcc')
source=(launcher.{c,ini,rc} {macros,version}.h Makefile {mingw32,mingw64,msys2}.ico)
md5sums=('e21db11d21f95aab30966a8c528efd9b'
'7ab96cb34fef046e4839e270f9397a32'
'3a3c9fd8d083716e5efd759641eb4f31'
'57a40ae9972dac94df0830a1ab480895'
'fef245f65b6826502b953b81fb397d97'
'8d3fa1f8eb06343a13b72299c164f6cd'
'797a8ea3012b22705caadcb17b1291c2'
'0237b204a9d09dcadc955b435cefd311'
'292ad5cdd78abac9d694cc06819a96fc')
pkgver() {
local _major=$(cat version.h | grep -F 'VER_MAJOR' | head -1 | sed -e 's/.* //')
local _minor=$(cat version.h | grep -F 'VER_MINOR' | head -1 | sed -e 's/.* //')
printf "%s.%s.%s.%s" "${_major}" "${_minor}" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}
build() {
make PREFIX=/opt/bin/${CARCH}-w64-mingw32-
}
package() {
cp {mingw32,mingw64,msys2}.{exe,ini} "${pkgdir}"
}

View File

@@ -6,4 +6,4 @@ A helper for launching MSYS2 shells. Features blink-less launching and correct t
Installation
------------
Just `make` and put the executables inside your MSYS2 root.
Just `make` and put the executables inside your MSYS2 root. Needs mintty v2.1.6 or newer (unreleased at the time of writing).

BIN
cygwin.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

View File

@@ -1,15 +1,8 @@
#define _UNICODE
#define _WIN32_WINNT 0x0601
#define WIN32_LEAN_AND_MEAN
#define PSAPI_VERSION 1
#include <windows.h>
#include <objbase.h>
#include <propvarutil.h>
#include <shobjidl.h>
#include <shellapi.h>
#include <propsys.h>
#include <propkey.h>
#include <processthreadsapi.h>
#include <psapi.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
@@ -17,25 +10,34 @@
#include "macros.h"
static void ShowError(const char* desc, const char* err, const long code) {
char msg[1024];
// if any of the properties change, it's best to use a brand new AppID
#define APPID_REVISION 9
sprintf(msg, "%s. Reason: %s (0x%lx)", desc, err, code);
MessageBox(NULL, msg, "Launcher error", MB_ICONEXCLAMATION | MB_OK);
static void ShowError(const wchar_t* desc, const wchar_t* err, const long code) {
wchar_t msg[1024];
swprintf(msg, 1024, L"%s. Reason: %s (0x%lx)", desc, err, code);
MessageBox(NULL, msg, L"Launcher error", MB_ICONEXCLAMATION | MB_OK);
}
static void ShowLastError(const char* desc) {
static void ShowLastError(const wchar_t* desc) {
DWORD code;
char* err;
wchar_t* err;
code = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&err, 0, NULL);
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&err, 0, NULL);
ShowError(desc, err, code);
LocalFree(err);
}
static void ShowErrno(const wchar_t* desc) {
wchar_t* err;
PROCESS_INFORMATION StartChild(const wchar_t* cmdline) {
err = _wcserror(errno);
ShowError(desc, err, errno);
}
static PROCESS_INFORMATION StartChild(wchar_t* cmdline) {
STARTUPINFOW si;
PROCESS_INFORMATION pi;
DWORD code;
@@ -44,126 +46,189 @@ PROCESS_INFORMATION StartChild(const wchar_t* cmdline) {
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
SetLastError(0);
code = CreateProcessW(NULL, (wchar_t*)cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
code = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (code == 0) {
ShowLastError("Could not start the shell");
ShowLastError(L"Could not start the shell");
ShowError(L"The command was", cmdline, 0);
return pi;
}
return pi;
}
static int SetEnv(const char* msystem) {
static wchar_t* SetEnv(wchar_t* conffile) {
int code;
char* env;
const char* err;
const char prefix[] = "MSYSTEM=";
size_t buflen;
size_t expandedlen;
wchar_t* tmp;
wchar_t* buf;
wchar_t* expanded;
wchar_t* msystem;
FILE* handle;
env = (char*)alloca(strlen(prefix) + strlen(msystem) + 1);
strcpy(env, prefix);
strcat(env, msystem);
code = putenv(env);
msystem = NULL;
handle = _wfopen(conffile, L"rt");
if (handle == NULL) {
ShowErrno(L"Could not open configuration file");
return msystem;
}
buflen = 512;
buf = (wchar_t*)malloc(buflen * sizeof(wchar_t));
*buf = L'\0';
expandedlen = 2 * buflen;
expanded = (wchar_t*)malloc(expandedlen * sizeof(wchar_t));
while (true) {
tmp = fgetws(buf + wcslen(buf), buflen - wcslen(buf), handle);
if (tmp == NULL && !feof(handle)) {
ShowErrno(L"Could not read from configuration file");
return NULL;
}
tmp = buf + wcslen(buf) - 1;
if (!feof(handle) && *tmp != L'\n') {
buflen *= 2;
buf = (wchar_t*)realloc(buf, buflen * sizeof(wchar_t));
continue;
}
if (!feof(handle)) {
*tmp = L'\0';
}
if (*buf != L'\0' && *buf != L'#') {
tmp = wcschr(buf, L'=');
if (tmp != NULL) {
*tmp++ = L'\0';
while (expandedlen < 32768) {
code = ExpandEnvironmentStrings(tmp, expanded, expandedlen);
if ((size_t)code <= expandedlen) {
break;
}
expandedlen *= 2;
expanded = (wchar_t*)realloc(expanded, expandedlen * sizeof(wchar_t));
}
if ((*tmp != L'\0' && code == 0) || (size_t)code > expandedlen) {
ShowLastError(L"Could not expand string");
}
if (0 == wcscmp(L"MSYSTEM", buf)) {
msystem = _wcsdup(expanded);
if (msystem == NULL) {
ShowError(L"Could not duplicate string", expanded, 0);
return NULL;
}
}
code = SetEnvironmentVariable(buf, expanded);
if (code == 0) {
ShowLastError(L"Could not set environment variable");
}
} else {
ShowError(L"Could not parse environment line", buf, 0);
}
}
*buf = L'\0';
if (feof(handle)) {
break;
}
}
code = fclose(handle);
if (code != 0) {
err = strerror(errno);
ShowError("Could not set MSYSTEM", err, errno);
return 0;
ShowErrno(L"Could not close configuration file");
}
return 1;
return msystem;
}
struct handle_data {
unsigned long process_id;
HWND best_handle;
};
BOOL is_main_window(HWND handle)
{
return GetWindow(handle, GW_OWNER) == (HWND)0 && IsWindowVisible(handle);
}
BOOL CALLBACK enum_windows_callback(HWND handle, LPARAM lParam)
{
struct handle_data* data = (struct handle_data*)lParam;
unsigned long process_id = 0;
GetWindowThreadProcessId(handle, &process_id);
if (data->process_id != process_id || !is_main_window(handle)) {
return TRUE;
}
data->best_handle = handle;
return FALSE;
}
HWND find_main_window(unsigned long process_id)
{
struct handle_data data;
data.process_id = process_id;
data.best_handle = 0;
EnumWindows(enum_windows_callback, (LPARAM)&data);
return data.best_handle;
}
HRESULT SetAppUserModelProperty(IPropertyStore* store, const PROPERTYKEY* key, LPCWSTR value) {
PROPVARIANT propVariant;
HRESULT hr;
propVariant.vt = VT_LPWSTR;
hr = SHStrDupW(value, &propVariant.pwszVal);
if (FAILED(hr)) {
return hr;
}
hr = store->lpVtbl->SetValue(store, key, &propVariant);
if (FAILED(hr)) {
return hr;
}
return 0;
}
int main(int argc, char* argv[]) {
int wmain(int argc, wchar_t* argv[]) {
PROCESS_INFORMATION child;
DWORD code;
int res;
HWND window;
IPropertyStore* store;
HRESULT hr;
int code;
size_t buflen;
wchar_t* buf;
wchar_t msysdir[PATH_MAX], exepath[PATH_MAX];
int delay = 10;
wchar_t* tmp;
wchar_t* args;
wchar_t* msystem;
wchar_t msysdir[PATH_MAX];
wchar_t exepath[PATH_MAX];
wchar_t confpath[PATH_MAX];
UNUSED(argc);
UNUSED(argv);
code = GetModuleFileNameW(NULL, exepath, sizeof(exepath) / sizeof(exepath[0]));
code = GetModuleFileName(NULL, exepath, sizeof(exepath) / sizeof(exepath[0]));
if (code == 0) {
ShowLastError("Could not determine executable path");
ShowLastError(L"Could not determine executable path");
return __LINE__;
}
while (wcschr(exepath, L'\\') != NULL) {
wcschr(exepath, L'\\')[0] = L'/';
tmp = exepath;
while (true) {
tmp = wcschr(tmp, L'/');
if (tmp == NULL) {
break;
}
*tmp = L'\\';
}
wcscpy(msysdir, exepath);
if (wcsrchr(msysdir, L'/') != NULL) {
wcsrchr(msysdir, L'/')[0] = L'\0';
tmp = wcsrchr(msysdir, L'\\');
if (tmp == NULL) {
ShowError(L"Could not find root directory", msysdir, 0);
return __LINE__;
}
buflen = wcslen(msysdir) + 1000;
buf = (wchar_t*)alloca(buflen * sizeof(wchar_t));
*tmp = L'\0';
code = SetEnv(STRINGIFY_A(MSYSTEM));
if (code == 0) {
wcscpy(confpath, exepath);
tmp = confpath + wcslen(confpath) - 4;
if (0 != wcsicmp(L".exe", tmp)) {
ShowError(L"Could not find configuration file", confpath, 0);
return __LINE__;
}
*tmp++ = L'.';
*tmp++ = L'i';
*tmp++ = L'n';
*tmp++ = L'i';
if (argc > 1) {
code = SetEnvironmentVariable(L"CHERE_INVOKING", L"1");
if (code == 0) {
ShowLastError(L"Could not set environment variable");
}
}
msystem = SetEnv(confpath);
if (msystem == NULL) {
ShowError(L"Did not find the MSYSTEM variable", confpath, 0);
return __LINE__;
}
res = swprintf(buf, buflen, L"%s/usr/bin/mintty.exe -i '%s' /usr/bin/bash --login -i", msysdir, exepath);
if (res < 0) {
code = SetEnvironmentVariable(L"MSYSCON", L"mintty.exe");
if (code == 0) {
ShowLastError(L"Could not set environment variable");
}
// can break, but hopefully won't for most use cases
args = GetCommandLine();
if (args[0] == L'"') {
args++;
}
args += wcslen(argv[0]);
if (args[0] == L'"') {
args++;
}
code = -1;
buf = NULL;
buflen = 1024;
while (code < 0 && buflen < 8192) {
buf = (wchar_t*)realloc(buf, buflen * sizeof(wchar_t));
if (buf == NULL) {
ShowError(L"Could not allocate memory", L"", 0);
return __LINE__;
}
code = swprintf(buf, buflen, L"%s\\%s -i '%s' -o 'AppLaunchCmd=%s' -o 'AppID=%s.Shell.%s.%d' -o 'AppName=%s %s Shell' --store-taskbar-properties -- /usr/bin/bash --login %s %s", msysdir, STRINGIFY_W(SHELLPATH), exepath, exepath, STRINGIFY_W(PRODUCT), msystem, APPID_REVISION, STRINGIFY_W(PRODUCT), msystem, argc == 1 ? L"-i" : L"-c '$0 \"$@\"'", args);
buflen *= 2;
}
if (code < 0) {
ShowErrno(L"Could not write to buffer");
return __LINE__;
}
@@ -172,51 +237,8 @@ int main(int argc, char* argv[]) {
return __LINE__;
}
while (true) {
Sleep(delay);
window = find_main_window(GetProcessId(child.hProcess));
if (!window) {
delay *= 2;
if (delay > 60000) {
return __LINE__;
}
continue;
}
hr = SHGetPropertyStoreForWindow(window, &IID_IPropertyStore, (void**)&store);
if (FAILED(hr)) {
return __LINE__;
}
hr = SetAppUserModelProperty(store, &PKEY_AppUserModel_ID, L"MSYS2.Shell." STRINGIFY_W(MSYSTEM) L".7");
if (FAILED(hr)) {
return __LINE__;
}
hr = SetAppUserModelProperty(store, &PKEY_AppUserModel_RelaunchDisplayNameResource, L"MSYS2 " STRINGIFY_W(MSYSTEM) L" shell");
if (FAILED(hr)) {
return __LINE__;
}
hr = SetAppUserModelProperty(store, &PKEY_AppUserModel_RelaunchCommand, exepath);
if (FAILED(hr)) {
return __LINE__;
}
hr = SetAppUserModelProperty(store, &PKEY_AppUserModel_RelaunchIconResource, exepath);
if (FAILED(hr)) {
return __LINE__;
}
hr = store->lpVtbl->Commit(store);
if (FAILED(hr)) {
return __LINE__;
}
store->lpVtbl->Release(store);
store = NULL;
break;
}
free(buf);
buf = NULL;
return 0;
}

4
launcher.ini Normal file
View File

@@ -0,0 +1,4 @@
#MSYS=winsymlinks:nativestrict
#MSYS=error_start:mingw64/bin/qtcreator.exe|-debug|<process-id>
#CHERE_INVOKING=1
#PATH=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem

View File

@@ -1,15 +1,16 @@
#include "macros.h"
#include "version.h"
1 VERSIONINFO
FILEVERSION 0,1,0,0
FILEVERSION VER_MAJOR,VER_MINOR,0,0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "ProductName", "MSYS2"
VALUE "FileDescription", "MSYS2/" STRINGIFY_A(MSYSTEM) " shell launcher"
VALUE "FileVersion", "0.1"
VALUE "ProductName", STRINGIFY_A(PRODUCT)
VALUE "FileDescription", STRINGIFY_A(PRODUCT) " " STRINGIFY_A(MSYSTEM) " shell launcher"
VALUE "FileVersion", STRINGIFY_A(VER_MAJOR) "." STRINGIFY_A(VER_MINOR)
END
END

View File

@@ -1,3 +1,6 @@
#ifndef M2L_MACROS_H
#define M2L_MACROS_H
#define UNUSED(x) ((void)(x))
#define STRINGIFY_A_(x) #x
@@ -5,3 +8,5 @@
#define STRINGIFY_W_(x) L ## #x
#define STRINGIFY_W(x) STRINGIFY_W_(x)
#endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

7
version.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef M2L_VERSION_H
#define M2L_VERSION_H
#define VER_MAJOR 0
#define VER_MINOR 3
#endif