Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypp committed Mar 9, 2019
1 parent d672bb3 commit fa55cb3
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,43 @@ void update_browser_info (HWND hwnd, BROWSER_INFORMATION* pbi)

void init_browser_info (BROWSER_INFORMATION* pbi)
{
static LPCWSTR binNames[] = {
L"firefox.exe",
L"basilisk.exe",
L"palemoon.exe",
L"waterfox.exe",
L"dragon.exe",
L"iridium.exe",
L"iron.exe",
L"opera.exe",
L"slimjet.exe",
L"vivaldi.exe",
L"chromium.exe",
L"chrome.exe", // default
};

pbi->urls[0] = 0; // reset

// configure paths
StringCchCopy (pbi->cache_path, _countof (pbi->cache_path), _r_path_expand (L"%temp%\\" APP_NAME_SHORT L"Cache.bin"));

StringCchCopy (pbi->binary_dir, _countof (pbi->binary_dir), _r_path_expand (app.ConfigGet (L"ChromiumDirectory", L".\\bin")));
StringCchPrintf (pbi->binary_path, _countof (pbi->binary_path), L"%s\\%s", pbi->binary_dir, app.ConfigGet (L"ChromiumBinary", L"chrome.exe").GetString ());

if (!_r_fs_exists (pbi->binary_path))
{
for (size_t i = 0; i < _countof (binNames); i++)
{
StringCchPrintf (pbi->binary_path, _countof (pbi->binary_path), L"%s\\%s", pbi->binary_dir, binNames[i]);

if (_r_fs_exists (pbi->binary_path))
break;
}

if (!_r_fs_exists (pbi->binary_path))
StringCchPrintf (pbi->binary_path, _countof (pbi->binary_path), L"%s\\%s", pbi->binary_dir, app.ConfigGet (L"ChromiumBinary", L"chrome.exe").GetString ()); // fallback (use defaults)
}

StringCchPrintf (pbi->cache_path, _countof (pbi->cache_path), L"%s\\" APP_NAME_SHORT L"Cache_%d.bin", _r_path_expand (L"%TEMP%").GetString (), _r_str_hash (pbi->binary_path));

// get browser architecture...
if (_r_sys_validversion (5, 1, 0, VER_EQUAL) || _r_sys_validversion (5, 2, 0, VER_EQUAL))
pbi->architecture = 32; // winxp supports only 32-bit
Expand Down Expand Up @@ -545,7 +574,7 @@ void normallize_dir_name (LPWSTR name)
}
}

bool _app_unpack_7zip (HWND hwnd, BROWSER_INFORMATION* pbi, LPCWSTR* pnames, size_t names_count)
bool _app_unpack_7zip (HWND hwnd, BROWSER_INFORMATION* pbi, LPCWSTR binName)
{
#define kInputBufSize ((size_t)1 << 18)

Expand Down Expand Up @@ -638,28 +667,20 @@ bool _app_unpack_7zip (HWND hwnd, BROWSER_INFORMATION* pbi, LPCWSTR* pnames, siz
LPCWSTR destPath = (LPCWSTR)temp;
LPCWSTR fname = _r_path_extractfile (destPath);

if (!fname || !pnames)
if (!fname || !binName || !binName[0])
continue;

for (size_t j = 0; j < names_count; j++)
{
if (!pnames[j])
continue;

const size_t fname_len = _r_str_length (fname);

if (_wcsnicmp (fname, pnames[j], fname_len) == 0)
{
const size_t root_dir_len = _r_str_length (destPath) - fname_len;
const size_t fname_len = _r_str_length (fname);

normallize_dir_name ((LPWSTR)destPath);
if (_wcsnicmp (fname, binName, fname_len) == 0)
{
const size_t root_dir_len = _r_str_length (destPath) - fname_len;

root_dir_name = destPath;
root_dir_name.SetLength (root_dir_len);
root_dir_name.Trim (L"\\");
normallize_dir_name ((LPWSTR)destPath);

break;
}
root_dir_name = destPath;
root_dir_name.SetLength (root_dir_len);
root_dir_name.Trim (L"\\");
}
}
}
Expand Down Expand Up @@ -785,7 +806,7 @@ bool _app_unpack_7zip (HWND hwnd, BROWSER_INFORMATION* pbi, LPCWSTR* pnames, siz
return result;
}

bool _app_unpack_zip (HWND hwnd, BROWSER_INFORMATION* pbi, LPCWSTR* pnames, size_t names_count)
bool _app_unpack_zip (HWND hwnd, BROWSER_INFORMATION* pbi, LPCWSTR binName)
{
bool result = false;

Expand Down Expand Up @@ -817,32 +838,24 @@ bool _app_unpack_zip (HWND hwnd, BROWSER_INFORMATION* pbi, LPCWSTR* pnames, size
// count total size of unpacked files
total_size += ze.unc_size;

if (root_dir_name.IsEmpty () && pnames)
if (root_dir_name.IsEmpty () && binName && binName[0])
{
LPCWSTR fname = _r_path_extractfile (ze.name);

if (!fname)
continue;

for (size_t j = 0; j < names_count; j++)
{
if (!pnames[j])
continue;
const size_t fname_len = _r_str_length (fname);

const size_t fname_len = _r_str_length (fname);

if (_wcsnicmp (fname, pnames[j], fname_len) == 0)
{
const size_t root_dir_len = _r_str_length (ze.name) - fname_len;

normallize_dir_name (ze.name);
if (_wcsnicmp (fname, binName, fname_len) == 0)
{
const size_t root_dir_len = _r_str_length (ze.name) - fname_len;

root_dir_name = ze.name;
root_dir_name.SetLength (root_dir_len);
root_dir_name.Trim (L"\\");
normallize_dir_name (ze.name);

break;
}
root_dir_name = ze.name;
root_dir_name.SetLength (root_dir_len);
root_dir_name.Trim (L"\\");
}
}
}
Expand Down Expand Up @@ -934,32 +947,19 @@ bool _app_installupdate (HWND hwnd, BROWSER_INFORMATION* pbi, bool *pis_error)

bool result = false;

rstring origName = _r_path_extractfile (pbi->binary_path);

LPCWSTR binNames[] = {
origName.GetString (),
L"chrome.exe",
L"dragon.exe",
L"firefox.exe",
L"iridium.exe",
L"iron.exe",
L"slimjet.exe",
L"vivaldi.exe",
L"waterfox.exe",
L"opera.exe",
};
const rstring binName = _r_path_extractfile (pbi->binary_path);

const HZIP hzip = OpenZip (pbi->cache_path, nullptr);

if (IsZipHandleU (hzip))
{
CloseZip (hzip);

result = _app_unpack_zip (hwnd, pbi, binNames, _countof (binNames));
result = _app_unpack_zip (hwnd, pbi, binName);
}
else
{
result = _app_unpack_7zip (hwnd, pbi, binNames, _countof (binNames));
result = _app_unpack_7zip (hwnd, pbi, binName);
}

if (result)
Expand Down

0 comments on commit fa55cb3

Please sign in to comment.