void Setup() { testStagingDir = CreateTempDir(); testDownloadDir = CreateTempDir(); testPrintDataDir = CreateTempDir(); SETTINGS.Set(STAGING_DIR, testStagingDir); SETTINGS.Set(DOWNLOAD_DIR, testDownloadDir); SETTINGS.Set(PRINT_DATA_DIR, testPrintDataDir); }
void Setup() { testDataDir = CreateTempDir(); testPrintDataDir = CreateTempDir(); }
DWORD WINAPI InstallReactOS(HINSTANCE hInstance) { TCHAR szBuffer[MAX_PATH]; HANDLE token; TOKEN_PRIVILEGES privs; HKEY hKey; HINF hShortcutsInf; InitializeSetupActionLog(FALSE); LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS"); if (!InitializeProfiles()) { FatalError("InitializeProfiles() failed"); return 0; } CreateTempDir(L"TEMP"); CreateTempDir(L"TMP"); if (GetWindowsDirectory(szBuffer, sizeof(szBuffer) / sizeof(TCHAR))) { if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegSetValueExW(hKey, L"PathName", 0, REG_SZ, (LPBYTE)szBuffer, (wcslen(szBuffer) + 1) * sizeof(WCHAR)); RegSetValueExW(hKey, L"SystemRoot", 0, REG_SZ, (LPBYTE)szBuffer, (wcslen(szBuffer) + 1) * sizeof(WCHAR)); RegCloseKey(hKey); } PathAddBackslash(szBuffer); _tcscat(szBuffer, _T("system")); CreateDirectory(szBuffer, NULL); } if (!CommonInstall()) return 0; InstallWizard(); InstallSecurity(); SetAutoAdminLogon(); hShortcutsInf = SetupOpenInfFileW(L"shortcuts.inf", NULL, INF_STYLE_WIN4, NULL); if (hShortcutsInf == INVALID_HANDLE_VALUE) { FatalError("Failed to open shortcuts.inf"); return 0; } if (!CreateShortcuts(hShortcutsInf, L"ShortcutFolders")) { FatalError("CreateShortcuts() failed"); return 0; } SetupCloseInfFile(hShortcutsInf); /* ROS HACK, as long as NtUnloadKey is not implemented */ { NTSTATUS Status = NtUnloadKey(NULL); if (Status == STATUS_NOT_IMPLEMENTED) { /* Create the Administrator profile */ PROFILEINFOW ProfileInfo; HANDLE hToken; BOOL ret; ret = LogonUserW(AdminInfo.Name, AdminInfo.Domain, AdminInfo.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken); if (!ret) { FatalError("LogonUserW() failed!"); return 0; } ZeroMemory(&ProfileInfo, sizeof(PROFILEINFOW)); ProfileInfo.dwSize = sizeof(PROFILEINFOW); ProfileInfo.lpUserName = L"Administrator"; ProfileInfo.dwFlags = PI_NOUI; LoadUserProfileW(hToken, &ProfileInfo); CloseHandle(hToken); } else { DPRINT1("ROS HACK not needed anymore. Please remove it\n"); } } /* END OF ROS HACK */ SetupCloseInfFile(hSysSetupInf); SetSetupType(0); LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS done"); TerminateSetupActionLog(); if (AdminInfo.Name != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Name); if (AdminInfo.Domain != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Domain); if (AdminInfo.Password != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Password); /* Get shutdown privilege */ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token)) { FatalError("OpenProcessToken() failed!"); return 0; } if (!LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &privs.Privileges[0].Luid)) { FatalError("LookupPrivilegeValue() failed!"); return 0; } privs.PrivilegeCount = 1; privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (AdjustTokenPrivileges( token, FALSE, &privs, 0, (PTOKEN_PRIVILEGES)NULL, NULL) == 0) { FatalError("AdjustTokenPrivileges() failed!"); return 0; } ExitWindowsEx(EWX_REBOOT, 0); return 0; }
//FIXME: nuke this! char * Application::GetResourceAsPath (const Uri *resourceBase, const Uri *uri) { const char *filename; char *dirname, *path; char *canonicalized_filename; ManagedStreamCallbacks stream; unzFile zipfile; struct stat st; char buf[4096]; int nread; int fd; if (!get_resource_cb || !uri || uri->IsAbsolute ()) return NULL; // construct the path name for this resource filename = uri->ToString (); canonicalized_filename = Deployment::GetCurrent ()->CanonicalizeFileName (filename, false); path = g_build_filename (GetResourceRoot(), canonicalized_filename, NULL); g_free (canonicalized_filename); if (g_stat (path, &st) != -1) { // path exists, we're done return path; } // create the directory for our resource (keeping the relative path intact) dirname = g_path_get_dirname (path); if (g_mkdir_with_parents (dirname, 0700) == -1 && errno != EEXIST) { g_free (dirname); g_free (path); return NULL; } g_free (dirname); stream = get_resource_cb (resourceBase, uri); if (!stream.handle) { g_free (path); return NULL; } // reset the stream to 0 if (stream.CanSeek (stream.handle)) stream.Seek (stream.handle, 0, SEEK_SET); // create and save the buffer to disk if ((fd = g_open (path, O_WRONLY | O_CREAT | O_EXCL, 0600)) == -1) { stream.Close (stream.handle); g_free (path); return NULL; } // write the stream to disk do { if ((nread = stream.Read (stream.handle, buf, 0, sizeof (buf))) <= 0) break; if (write_all (fd, buf, (size_t) nread) == -1) { stream.Close (stream.handle); g_unlink (path); g_free (path); close (fd); return NULL; } } while (true); stream.Close (stream.handle); close (fd); // check to see if the resource is zipped if (!(zipfile = unzOpen (path))) { // nope, not zipped... return path; } // create a directory to contain our unzipped content if (!(dirname = CreateTempDir (path))) { unzClose (zipfile); g_free (dirname); g_unlink (path); g_free (path); return NULL; } // unzip the contents if (!ExtractAll (zipfile, dirname, CanonModeResource)) { RemoveDir (dirname); unzClose (zipfile); g_free (dirname); g_unlink (path); g_free (path); return NULL; } unzClose (zipfile); g_unlink (path); if (g_rename (dirname, path) == -1) { RemoveDir (dirname); g_free (dirname); g_free (path); return NULL; } g_free (dirname); return path; }
const char * Downloader::GetUnzippedPath () { char filename[256], *p; unz_file_info info; const char *name; GString *path; unzFile zip; size_t len; int fd; if (!this->filename) return NULL; if (!DownloadedFileIsZipped ()) return this->filename; if (!unzipdir && !(unzipdir = CreateTempDir (this->filename))) return NULL; if (unzipped) return unzipdir; // open the zip archive... if (!(zip = unzOpen (this->filename))) return NULL; path = g_string_new (unzipdir); g_string_append_c (path, G_DIR_SEPARATOR); len = path->len; unzipped = true; // extract all the parts do { if (unzOpenCurrentFile (zip) != UNZ_OK) break; unzGetCurrentFileInfo (zip, &info, filename, sizeof (filename), NULL, 0, NULL, 0); // convert filename to lowercase for (p = filename; *p; p++) { if (*p >= 'A' && *p <= 'Z') *p += 0x20; } if ((name = strrchr (filename, '/'))) { // make sure the full directory path exists, if not create it g_string_append_len (path, filename, name - filename); g_mkdir_with_parents (path->str, 0700); g_string_append (path, name); } else { g_string_append (path, filename); } if ((fd = g_open (path->str, O_WRONLY | O_CREAT | O_EXCL, 0600)) != -1) { if (!ExtractFile (zip, fd)) unzipped = false; } else if (errno != EEXIST) { unzipped = false; } g_string_truncate (path, len); unzCloseCurrentFile (zip); } while (unzGoToNextFile (zip) == UNZ_OK); g_string_free (path, true); unzClose (zip); return unzipdir; }
char * Downloader::GetDownloadedFilename (const char *partname) { LOG_DOWNLOADER ("Downloader::GetDownloadedFilename (%s)\n", filename); char *dirname, *path, *part; unzFile zipfile; struct stat st; int rv, fd; if (!filename) return NULL; if (!partname || !partname[0]) return g_strdup (filename); if (!DownloadedFileIsZipped ()) return NULL; if (!unzipdir && !(unzipdir = CreateTempDir (filename))) return NULL; part = g_ascii_strdown (partname, -1); path = g_build_filename (unzipdir, part, NULL); if ((rv = g_stat (path, &st)) == -1 && errno == ENOENT) { if (strchr (part, '/') != NULL) { // create the directory path dirname = g_path_get_dirname (path); rv = g_mkdir_with_parents (dirname, 0700); g_free (dirname); if (rv == -1 && errno != EEXIST) goto exception1; } // open the zip archive... if (!(zipfile = unzOpen (filename))) goto exception1; // locate the file we want to extract... (2 = case-insensitive) if (unzLocateFile (zipfile, partname, 2) != UNZ_OK) goto exception2; // open the requested part within the zip file if (unzOpenCurrentFile (zipfile) != UNZ_OK) goto exception2; // open the output file if ((fd = g_open (path, O_CREAT | O_WRONLY | O_TRUNC, 0600)) == -1) goto exception3; // extract the file from the zip archive... (closes the fd on success and fail) if (!ExtractFile (zipfile, fd)) goto exception3; unzCloseCurrentFile (zipfile); unzClose (zipfile); } else if (rv == -1) { // irrecoverable error goto exception0; } g_free (part); return path; exception3: unzCloseCurrentFile (zipfile); exception2: unzClose (zipfile); exception1: g_free (part); exception0: g_free (path); return NULL; }