void printer_write(char * data, uint len) { if (printer) { char * buf = malloc(len + 1); for (uint i = 0; i < len; i++) { if (data[i]) buf[i] = data[i]; else buf[i] = ' '; } buf[len] = '\0'; wchar * wdata = cs__mbstowcs(buf); write(pd, wdata, wcslen(wdata) * sizeof(wchar)); free(buf); free(wdata); } }
void win_open(wstring wpath) { wstring p = wpath; while (iswalpha(*p)) p++; if (*wpath == '\\' || *p == ':' || wcsncmp(W("www."), wpath, 4) == 0) { // Looks like it's a Windows path or URI shell_exec(wpath); } else { // Need to convert POSIX path to Windows first if (support_wsl) { #ifdef debug_wsl printf("open <%ls>\n", wpath); #endif if (wcsncmp(wpath, W("/mnt/"), 5) == 0) { wchar * unwsl = newn(wchar, wcslen(wpath) + 6); wcscpy(unwsl, W("/cygdrive")); wcscat(unwsl, wpath + 4); delete(wpath); wpath = unwsl; } else if (*wpath == '/') { // prepend %LOCALAPPDATA%\lxss[\rootfs] char * appd = getenv("LOCALAPPDATA"); if (appd) { wchar * wappd = cs__mbstowcs(appd); appd = path_win_w_to_posix(wappd); free(wappd); wappd = cs__mbstowcs(appd); free(appd); bool rootfs_mount = true; for (uint i = 0; i < lengthof(lxss_mounts); i++) { if (ispathprefixw(lxss_mounts[i].w, wpath)) { rootfs_mount = false; break; } } wchar * unwsl = newn(wchar, wcslen(wappd) + wcslen(wpath) + 13); wcscpy(unwsl, wappd); free(wappd); wcscat(unwsl, W("/lxss")); if (rootfs_mount) wcscat(unwsl, W("/rootfs")); wcscat(unwsl, wpath); delete(wpath); wpath = unwsl; } } } wstring conv_wpath = child_conv_path(wpath); #ifdef debug_wsl printf("open <%ls> <%ls>\n", wpath, conv_wpath); #endif delete(wpath); if (conv_wpath) shell_exec(conv_wpath); else message_box(0, strerror(errno), null, MB_ICONERROR, null); } }