summaryrefslogtreecommitdiffstats
path: root/chrome/installer/mini_installer
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 16:22:37 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 16:22:37 +0000
commitbedaf4ab43643d8c9f87014cb5841638d08ef884 (patch)
tree3878ef266d25b82dfd950363fedf6f8a5c989d6d /chrome/installer/mini_installer
parente4cfddb3796bacb968607d17024d77540b665ca2 (diff)
downloadchromium_src-bedaf4ab43643d8c9f87014cb5841638d08ef884.zip
chromium_src-bedaf4ab43643d8c9f87014cb5841638d08ef884.tar.gz
chromium_src-bedaf4ab43643d8c9f87014cb5841638d08ef884.tar.bz2
Use current dir as working directory if %TEMP% directory doesnt work.
BUG=6471 TEST=set TMP to invalid dir and run mini_installer.exe, it should still work. Review URL: http://codereview.chromium.org/125068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/mini_installer')
-rw-r--r--chrome/installer/mini_installer/mini_installer.cc46
1 files changed, 29 insertions, 17 deletions
diff --git a/chrome/installer/mini_installer/mini_installer.cc b/chrome/installer/mini_installer/mini_installer.cc
index 722f404..9fe42c0 100644
--- a/chrome/installer/mini_installer/mini_installer.cc
+++ b/chrome/installer/mini_installer/mini_installer.cc
@@ -233,7 +233,6 @@ BOOL CALLBACK OnResourceFound(HMODULE module, const wchar_t* type,
return TRUE;
}
-
// Finds and writes to disk resources of various types. Returns false
// if there is a problem in writing any resource to disk. setup.exe resource
// can come in one of three possible forms:
@@ -285,7 +284,7 @@ bool UnpackBinaryResources(HMODULE module, const wchar_t* base_path,
int exit_code = 0;
if (!RunProcessAndWait(NULL, cmd_line, &exit_code) ||
(exit_code != 0))
- return FALSE;
+ return false;
if (!SafeStrCopy(setup_path, setup_path_size, setup_dest_path))
return false;
@@ -423,24 +422,15 @@ void DeleteExtractedFiles(const wchar_t* base_path,
::RemoveDirectory(base_path);
}
-// Creates and returns a temporary directory that can be used to extract
-// mini_installer payload.
-bool GetWorkDir(HMODULE module, wchar_t* work_dir) {
- wchar_t base_path[MAX_PATH];
- DWORD len = ::GetTempPath(_countof(base_path), base_path);
- if (len >= _countof(base_path) || len <= 0) {
- // Problem in getting TEMP path so just use current directory as base path
- len = ::GetModuleFileName(module, base_path, _countof(base_path));
- if (len >= _countof(base_path) || len <= 0)
- return false; // Can't even get current directory? Return with error.
- wchar_t* name = GetNameFromPathExt(base_path, len);
- *name = L'\0';
- }
-
+// Creates a temporary directory under |base_path| and returns the full path
+// of created directory in |work_dir|. If successful return true, otherwise
+// false.
+bool CreateWorkDir(const wchar_t* base_path, wchar_t* work_dir) {
wchar_t temp_name[MAX_PATH];
if (!GetTempFileName(base_path, kTempPrefix, 0, temp_name))
return false; // Didn't get any temp name to use. Return error.
- len = GetLongPathName(temp_name, work_dir, _countof(temp_name));
+
+ DWORD len = GetLongPathName(temp_name, work_dir, _countof(temp_name));
if (len >= _countof(temp_name) || len <= 0)
return false; // Couldn't get full path to temp dir. Return error.
@@ -449,6 +439,28 @@ bool GetWorkDir(HMODULE module, wchar_t* work_dir) {
if (!::DeleteFile(work_dir) || !::CreateDirectory(work_dir, NULL))
return false; // What's the use of temp dir if we can not create it?
::lstrcat(work_dir, L"\\");
+
+ return true;
+}
+
+// Creates and returns a temporary directory that can be used to extract
+// mini_installer payload.
+bool GetWorkDir(HMODULE module, wchar_t* work_dir) {
+ wchar_t base_path[MAX_PATH];
+ DWORD len = ::GetTempPath(_countof(base_path), base_path);
+ if (len >= _countof(base_path) || len <= 0 ||
+ !CreateWorkDir(base_path, work_dir)) {
+ // Problem in creating work dir under TEMP path, so try using current
+ // directory as base path.
+ len = ::GetModuleFileName(module, base_path, _countof(base_path));
+ if (len >= _countof(base_path) || len <= 0)
+ return false; // Can't even get current directory? Return with error.
+
+ wchar_t* name = GetNameFromPathExt(base_path, len);
+ *name = L'\0';
+
+ return CreateWorkDir(base_path, work_dir);
+ }
return true;
}