diff options
author | Simon Rettberg | 2016-03-18 15:05:56 +0100 |
---|---|---|
committer | Simon Rettberg | 2016-03-18 15:05:56 +0100 |
commit | 240c4b062a4e8bf9e76fbee5217646385a4caa58 (patch) | |
tree | 02d630952c97359eebd967aa88c0897e5a405973 | |
parent | [run-virt] More progress on openslx.exe (diff) | |
download | tm-scripts-240c4b062a4e8bf9e76fbee5217646385a4caa58.tar.gz tm-scripts-240c4b062a4e8bf9e76fbee5217646385a4caa58.tar.xz tm-scripts-240c4b062a4e8bf9e76fbee5217646385a4caa58.zip |
[run-virt/vmware] Error messages if mounting in win fails, fallback logic
6 files changed, 90 insertions, 28 deletions
diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_virtual_floppy.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_virtual_floppy.inc index 2fdebf4c..48033d41 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_virtual_floppy.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_virtual_floppy.inc @@ -41,11 +41,11 @@ touch "${SHARES}" chmod 0600 "${SHARES}" if pwdaemon --query "${TMPHOME}/.pwsocket" > "${SHARES}"; then sed -i 's/^/192.168.101.1\t/' "${SHARES}" # TODO: Depending on nettype (in case we have != nat some day) - if [ -e "${TMPHOME}/.home" ]; then + if [ "${SHARE_REMAP_MODE}" = 1 -o "${SHARE_REMAP_MODE}" = 2 ] && [ -e "${TMPHOME}/.home" ]; then NETHOME=$(cat "${TMPHOME}/.home") - [ -z "$SLX_HOME_DRIVE" ] && SLX_HOME_DRIVE="H:" + [ -z "$SHARE_HOME_DRIVE" ] && SHARE_HOME_DRIVE="H:" # Tab between items, so spaces can be used! - echo "${NETHOME} ${SLX_HOME_DRIVE} Home-Verzeichnis" >> "${SHARES}" + echo "${NETHOME} ${SHARE_HOME_DRIVE} Home-Verzeichnis" >> "${SHARES}" fi for VAR in ${!SLX_SHARE_*}; do echo "${!VAR}" >> "${SHARES}" diff --git a/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe b/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe Binary files differindex 7b71ba90..0123d474 100755 --- a/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe +++ b/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe diff --git a/remote/modules/run-virt/winres.c b/remote/modules/run-virt/winres.c index e4fce258..0ac24105 100644 --- a/remote/modules/run-virt/winres.c +++ b/remote/modules/run-virt/winres.c @@ -167,7 +167,7 @@ static void CALLBACK setupNetworkDrives(HWND hWnd, UINT uMsg, UINT_PTR idEvent, } } // Finished successfully or failed completely - if (_folderStatus != FS_OK) { + if (_folderStatus != FS_OK && (_remapMode == RM_NATIVE_FALLBACK || _remapMode == RM_VMWARE)) { remapViaSharedFolder(); } } @@ -179,6 +179,7 @@ static void CALLBACK setupNetworkDrives(HWND hWnd, UINT uMsg, UINT_PTR idEvent, MessageBoxA(NULL, "Kein Home-Verzeichnis gefunden. Bitte nichts Wichtiges in der VM speichern, sondern z.B. einen USB-Stick verwenden.", "Warnung", MB_ICONERROR); } } + return; exit_func: bInProc = FALSE; } @@ -226,6 +227,9 @@ static void loadPaths() remap.other = GetPrivateProfileIntA("remap", "other", 0, SETTINGS_FILE) != 0; _createMissingRemap = GetPrivateProfileIntA("openslx", "createMissingRemap", 1, SETTINGS_FILE) != 0; _remapMode = GetPrivateProfileIntA("openslx", "remapMode", RM_NATIVE_FALLBACK, SETTINGS_FILE); + if (_remapMode == RM_NONE) { + _folderStatus = FS_OK; + } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) @@ -645,6 +649,7 @@ static void postSuccessfulMount(const netdrive_t *d, wchar_t *letter) if (_remapMode == RM_NATIVE_FALLBACK || (isVmware && _remapMode == RM_VMWARE) || (!isVmware && _remapMode == RM_NATIVE)) { + alog("Patch user paths (%d)", (int)isVmware); patchUserPaths(letter); } } @@ -742,13 +747,36 @@ static BOOL mountNetworkShares() static void remapViaSharedFolder() { + static const char* homeDirA = "\\\\vmware-host\\Shared Folders\\home"; // thiscase! + static const wchar_t* homeDirW = L"\\\\vmware-host\\shared folders\\home"; // lowercase! + static BOOL once = FALSE; + if (once) return; + once = TRUE; netdrive_t d; - d.path = (char*)"\\\\vmware-host\\Shared Folders\\home"; + d.path = (char*)homeDirA; d.letter = (char*)"H:"; d.shortcut = (char*)"Home-Verzeichnis"; d.user = NULL; d.pass = NULL; d.success = FALSE; + // See if it's already mapped + wchar_t letter[5] = L"C:\\"; + char buffer[600]; + UNIVERSAL_NAME_INFOW *uni = (UNIVERSAL_NAME_INFOW*)buffer; + for (letter[0] = 'D'; letter[0] <= 'Z'; ++letter[0]) { + wlog(L"Checking %s", letter); + DWORD len = (DWORD)sizeof(buffer); + if (NO_ERROR == WNetGetUniversalNameW(letter, UNIVERSAL_NAME_INFO_LEVEL, uni, &len)) { + _wcslwr(uni->lpUniversalName); + wlog(L"Is %s", uni->lpUniversalName); + if (wcscmp(uni->lpUniversalName, homeDirW) == 0) { + letter[2] = '\0'; + postSuccessfulMount(&d, letter); + return; + } + } + } + // Map vmware shared folder mountNetworkShare(&d); } @@ -807,12 +835,14 @@ static HRESULT createFolderShortcut(wchar_t* targetDir, wchar_t* linkFile, wchar if (SUCCEEDED(hRes)) { wchar_t explorer[MAX_PATH]; StringCchPrintfW(explorer, MAX_PATH, L"\"%s\\explorer.exe\"", windowsPath); - /* Set the fields in the IShellLink object */ + // Set the fields in the IShellLink object hRes = pShellLink->lpVtbl->SetPath(pShellLink, explorer); hRes = pShellLink->lpVtbl->SetArguments(pShellLink, targetDir); if (comment != NULL) { hRes = pShellLink->lpVtbl->SetDescription(pShellLink, comment); } + StringCchPrintfW(explorer, MAX_PATH, L"%s\\system32\\imageres.dll", windowsPath); + hRes = pShellLink->lpVtbl->SetIconLocation(pShellLink, explorer, 137); /* Use the IPersistFile object to save the shell link */ hRes = pShellLink->lpVtbl->QueryInterface( @@ -832,12 +862,26 @@ static HRESULT createFolderShortcut(wchar_t* targetDir, wchar_t* linkFile, wchar // Patch user directories -static BOOL patchRegPath(HKEY hKey, wchar_t *letter, wchar_t *value, ...) +static BOOL patchRegPath(BOOL *patchOk, BOOL *anyMapped, HKEY hKey, wchar_t *letter, wchar_t *value, ...) { wchar_t *folder = NULL; wchar_t first[MAX_PATH] = {0}; wchar_t path[MAX_PATH]; + wchar_t oldvalue[MAX_PATH]; va_list args; + LONG ret; + DWORD type; + DWORD len; + // Let's check the path in the registry first + len = (DWORD)(sizeof(oldvalue) - sizeof(wchar_t)); + ret = RegQueryValueExW(hKey, value, NULL, &type, (BYTE*)oldvalue, &len); + if (ret == ERROR_SUCCESS && (type == REG_EXPAND_SZ || type == REG_SZ)) { + len /= 2; + oldvalue[len] = '\0'; + if (towlower(oldvalue[0]) == towlower(letter[0]) && folderExists(oldvalue)) // Same drive, folder exists, yay + return TRUE; + } + // Old registry value doesn't fit - figure out new value va_start(args, value); while ((folder = va_arg(args, wchar_t*)) != NULL) { StringCchPrintfW(path, MAX_PATH, L"%s\\%s", letter, folder); @@ -860,11 +904,20 @@ static BOOL patchRegPath(HKEY hKey, wchar_t *letter, wchar_t *value, ...) folder = first; CreateDirectoryW(folder, NULL); } - LONG ret = RegSetValueExW(hKey, value, 0, REG_SZ, (BYTE*)folder, (wcslen(folder) + 1) * sizeof(wchar_t)); - if (ret != ERROR_SUCCESS) { - alog("Setting reg key failed (return value %ld)", (long)ret); + _wcslwr(folder); + _wcslwr(oldvalue); + if (wcscmp(folder, oldvalue) == 0) { + // Path already in registry, don't update + return TRUE; + } + ret = RegSetValueExW(hKey, value, 0, REG_SZ, (BYTE*)folder, (wcslen(folder) + 1) * sizeof(wchar_t)); + if (ret == ERROR_SUCCESS) { + *anyMapped = TRUE; + return TRUE; } - return ret == ERROR_SUCCESS; + wlog(L"Setting reg key %s to %s failed (return value %ld)", value, folder, (long)ret); + *patchOk = FALSE; + return FALSE; } static void patchUserPaths(wchar_t *letter) @@ -873,7 +926,8 @@ static void patchUserPaths(wchar_t *letter) HKEY hKey; BOOL patchOk = TRUE; BOOL killOk = FALSE; - _folderStatus = 0; + BOOL anyMapped = FALSE; + _folderStatus = FS_ERROR; ret = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 0, KEY_WOW64_64KEY | KEY_READ | KEY_WRITE, &hKey); @@ -883,27 +937,31 @@ static void patchUserPaths(wchar_t *letter) } // Ha! if (remap.other) { - patchOk = patchRegPath(hKey, letter, L"{56784854-C6CB-462B-8169-88E350ACB882}", L"Contacts", L"Profile\\Contacts", L"Kontakte", NULL) && patchOk; - patchOk = patchRegPath(hKey, letter, L"Favorites", L"Favorites", L"Profile\\Favorites", L"Favoriten", NULL) && patchOk; - patchOk = patchRegPath(hKey, letter, L"{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}", L"Searches", L"Profile\\Searches", NULL) && patchOk; - patchOk = patchRegPath(hKey, letter, L"{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}", L"Links", L"Profile\\Links", NULL) && patchOk; - patchOk = patchRegPath(hKey, letter, L"{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}", L"Saved Games", L"SavedGames", L"Profile\\SavedGames", NULL) && patchOk; + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"{56784854-C6CB-462B-8169-88E350ACB882}", L"Contacts", L"Profile\\Contacts", L"Kontakte", NULL); + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"Favorites", L"Favorites", L"Profile\\Favorites", L"Favoriten", NULL); + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}", L"Searches", L"Profile\\Searches", NULL); + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}", L"Links", L"Profile\\Links", NULL); + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}", L"Saved Games", L"SavedGames", L"Profile\\SavedGames", NULL); } if (remap.media) { - patchOk = patchRegPath(hKey, letter, L"My Video", L"Videos", L"My Videos", L"Eigene Videos", NULL) && patchOk; - patchOk = patchRegPath(hKey, letter, L"My Pictures", L"Pictures", L"My Pictures", L"Eigene Bilder", L"Bilder", NULL) && patchOk; - patchOk = patchRegPath(hKey, letter, L"My Music", L"Music", L"My Music", L"Eigene Musik", L"Musik", NULL) && patchOk; + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"My Video", L"Videos", L"My Videos", L"Eigene Videos", NULL); + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"My Pictures", L"Pictures", L"My Pictures", L"Eigene Bilder", L"Bilder", NULL); + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"My Music", L"Music", L"My Music", L"Eigene Musik", L"Musik", NULL); } if (remap.downloads) { - patchOk = patchRegPath(hKey, letter, L"{374DE290-123F-4565-9164-39C4925E467B}", L"Downloads", L"Profile\\Downloads", NULL) && patchOk; + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"{374DE290-123F-4565-9164-39C4925E467B}", L"Downloads", L"Profile\\Downloads", NULL); } if (remap.documents) { - patchOk = patchRegPath(hKey, letter, L"Personal", L"Documents", L"Dokumente", L"My Documents", L"Eigene Dateien", NULL) && patchOk; + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"Personal", L"Documents", L"Dokumente", L"My Documents", L"Eigene Dateien", NULL); } if (remap.desktop) { - patchOk = patchRegPath(hKey, letter, L"Desktop", L"Windows Desktop", L"Desktop", L"Arbeitsfl\u00E4che", NULL) && patchOk; + patchRegPath(&patchOk, &anyMapped, hKey, letter, L"Desktop", L"Windows Desktop", L"Desktop", L"Arbeitsfl\u00E4che", NULL); } RegCloseKey(hKey); + if (!anyMapped) { + _folderStatus = FS_OK; + return; + } // Kill explorer PROCESSENTRY32W entry; entry.dwSize = sizeof(PROCESSENTRY32W); @@ -927,7 +985,7 @@ static void patchUserPaths(wchar_t *letter) } CloseHandle(snapshot); if (patchOk && killOk) { - _folderStatus = 1; + _folderStatus = FS_OK; } } diff --git a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file.inc b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file.inc index 5d33ce16..b9e998ea 100644 --- a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file.inc +++ b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file.inc @@ -172,10 +172,12 @@ real_core_count="$cpu_cores" # to a different value than the virtual number of cores per virtual CPU. cores_per_socket="$cpu_cores" -if [ "x$shfolders" != "xFALSE" ]; then +if [ "x$shfolders" != "xFALSE" ] && [ "$SHARE_REMAP_MODE" != 1 ]; then ENABLE_SHARE='sharedFolder.option = "alwaysEnabled"' + HGFS_DISABLED="FALSE" else ENABLE_SHARE='' + HGFS_DISABLED="TRUE" fi [ "$mem" -ge "$MAXMEM" ] && mem="$MAXMEM" diff --git a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file_legacy.inc b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file_legacy.inc index 7418a053..7332c79a 100644 --- a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file_legacy.inc +++ b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file_legacy.inc @@ -159,10 +159,12 @@ create_vmware_config_file_legacy() { # to a different value than the virtual number of cores per virtual CPU. cores_per_socket="$cpu_cores" - if [ "x$shfolders" != "xFALSE" ]; then + if [ "x$shfolders" != "xFALSE" ] && [ "$SHARE_REMAP_MODE" != 1 ]; then ENABLE_SHARE='sharedFolder.option = "alwaysEnabled"' + HGFS_DISABLED="FALSE" else ENABLE_SHARE='' + HGFS_DISABLED="TRUE" fi [ "$mem" -ge "$MAXMEM" ] && mem="$MAXMEM" @@ -293,7 +295,7 @@ create_vmware_config_file_legacy() { mainMem.useNamedFile = "TRUE" snapshot.disabled = "TRUE" tools.syncTime = "TRUE" - isolation.tools.hgfs.disable = "FALSE" + isolation.tools.hgfs.disable = "$HGFS_DISABLED" hgfs.mapRootShare = "TRUE" isolation.tools.dnd.disable = "FALSE" isolation.tools.copy.enable = "TRUE" diff --git a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/parse_vmx.inc b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/parse_vmx.inc index cdc2710c..a8136513 100644 --- a/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/parse_vmx.inc +++ b/remote/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/parse_vmx.inc @@ -97,7 +97,7 @@ HEREEND # Isolation tools: settings # It should be verified whether and when entries necessary cat >> "$TMPDIR/$IMGUUID" <<-HEREEND -isolation.tools.hgfs.disable = "FALSE" +isolation.tools.hgfs.disable = "$HGFS_DISABLED" isolation.tools.dnd.disable = "FALSE" isolation.tools.copy.enable = "TRUE" isolation.tools.paste.enabled = "TRUE" |