Skip to content

Commit

Permalink
Merge pull request 'Online-installer: add dev-channel support' (#104)…
Browse files Browse the repository at this point in the history
… from feature/online-installer-dev-channel into develop
  • Loading branch information
maxkadushkin committed Nov 28, 2024
2 parents 2dd5db7 + a1904bf commit b5beda7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 94 deletions.
42 changes: 8 additions & 34 deletions win-linux/extras/online-installer/OnlineInstaller.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,13 @@ DEFINES += APP_LANG_PATH=\"./langs/langs.iss\"

OTHER_FILES += $$PWD/res/langs/langs.iss

ENV_URL_INSTALL_X64 = $$(DESKTOP_URL_INSTALL_CHANNEL_X64)
!isEmpty(ENV_URL_INSTALL_X64) {
DEFINES += URL_INSTALL_X64=\\\"$${ENV_URL_INSTALL_X64}\\\"
}
ENV_URL_INSTALL = $$(DESKTOP_URL_INSTALL_CHANNEL)
isEmpty(ENV_URL_INSTALL): DEFINES += URL_INSTALL=\\\"\\\"
else: DEFINES += URL_INSTALL=\\\"$${ENV_URL_INSTALL}\\\"

ENV_URL_INSTALL_X86 = $$(DESKTOP_URL_INSTALL_CHANNEL_X86)
!isEmpty(ENV_URL_INSTALL_X86) {
DEFINES += URL_INSTALL_X86=\\\"$${ENV_URL_INSTALL_X86}\\\"
}
ENV_URL_INSTALL_DEV = $$(DESKTOP_URL_INSTALL_DEV_CHANNEL)
isEmpty(ENV_URL_INSTALL_DEV): DEFINES += URL_INSTALL_DEV=\\\"\\\"
else: DEFINES += URL_INSTALL_DEV=\\\"$${ENV_URL_INSTALL_DEV}\\\"

ENV_URL_INSTALL_X64_XP = $$(DESKTOP_URL_INSTALL_CHANNEL_X64_XP)
!isEmpty(ENV_URL_INSTALL_X64_XP) {
DEFINES += URL_INSTALL_X64_XP=\\\"$${ENV_URL_INSTALL_X64_XP}\\\"
}

ENV_URL_INSTALL_X86_XP = $$(DESKTOP_URL_INSTALL_CHANNEL_X86_XP)
!isEmpty(ENV_URL_INSTALL_X86_XP) {
DEFINES += URL_INSTALL_X86_XP=\\\"$${ENV_URL_INSTALL_X86_XP}\\\"
}

ENV_URL_INSTALL_X64_MSI = $$(DESKTOP_URL_INSTALL_CHANNEL_X64_MSI)
!isEmpty(ENV_URL_INSTALL_X64_MSI) {
DEFINES += URL_INSTALL_X64_MSI=\\\"$${ENV_URL_INSTALL_X64_MSI}\\\"
}

ENV_URL_INSTALL_X86_MSI = $$(DESKTOP_URL_INSTALL_CHANNEL_X86_MSI)
!isEmpty(ENV_URL_INSTALL_X86_MSI) {
DEFINES += URL_INSTALL_X86_MSI=\\\"$${ENV_URL_INSTALL_X86_MSI}\\\"
}

message(install x64 url: \\\"$$ENV_URL_INSTALL_X64\\\")
message(install x86 url: \\\"$$ENV_URL_INSTALL_X86\\\")
message(install x64 xp url: \\\"$$ENV_URL_INSTALL_X64_XP\\\")
message(install x86 xp url: \\\"$$ENV_URL_INSTALL_X86_XP\\\")
message(install x64 msi url: \\\"$$ENV_URL_INSTALL_X64_MSI\\\")
message(install x86 msi url: \\\"$$ENV_URL_INSTALL_X86_MSI\\\")
message(install url: \\\"$$ENV_URL_INSTALL\\\")
message(install dev url: \\\"$$ENV_URL_INSTALL_DEV\\\")
39 changes: 9 additions & 30 deletions win-linux/extras/online-installer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,10 @@
#include <locale>
#include "resource.h"
#include "utils.h"
#include "baseutils.h"
#include "translator.h"
#include "../../src/defines.h"
#include "../../src/prop/defines_p.h"

#ifndef URL_INSTALL_X64
# define URL_INSTALL_X64 ""
#endif
#ifndef URL_INSTALL_X86
# define URL_INSTALL_X86 ""
#endif
#ifndef URL_INSTALL_X64_XP
# define URL_INSTALL_X64_XP ""
#endif
#ifndef URL_INSTALL_X86_XP
# define URL_INSTALL_X86_XP ""
#endif
#ifndef URL_INSTALL_X64_MSI
# define URL_INSTALL_X64_MSI ""
#endif
#ifndef URL_INSTALL_X86_MSI
# define URL_INSTALL_X86_MSI ""
#endif
#define _TR(str) Translator::tr(str).c_str()
#define WINDOW_SIZE Size(768, 480)

Expand All @@ -35,14 +16,12 @@ int WINAPI _tWinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInstance, _In
UNREFERENCED_PARAMETER(hPrevInstance);
int num_args = 0;
if (LPTSTR *args = CommandLineToArgvW(lpCmdLine, &num_args)) {
for (int i = 0; i < num_args; i++) {
if (lstrcmpi(args[i], _T("--log")) == 0) {
NS_Logger::AllowWriteLog();
break;
}
}
NS_Utils::parseCmdArgs(num_args, args);
LocalFree(args);
}
if (NS_Utils::cmdArgContains(_T("--log")))
NS_Logger::AllowWriteLog();

std::locale::global(std::locale(""));
LCID lcid = MAKELCID(GetUserDefaultUILanguage(), SORT_DEFAULT);
Translator lang(lcid, IDT_TRANSLATIONS);
Expand All @@ -62,11 +41,11 @@ int WINAPI _tWinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInstance, _In
wstring url_or_path, arch;
bool app_installed = NS_Utils::IsAppInstalled(url_or_path, &arch);
if (!app_installed) {
if (NS_Utils::IsWin64()) {
url_or_path = (Utils::getWinVersion() <= Utils::WinVer::WinVista) ? _T(URL_INSTALL_X64_XP) : _T(URL_INSTALL_X64);
} else {
url_or_path = (Utils::getWinVersion() <= Utils::WinVer::WinVista) ? _T(URL_INSTALL_X86_XP) : _T(URL_INSTALL_X86);
}
url_or_path = NS_Utils::cmdArgContains(_T("--appcast-dev-channel")) ? _T(URL_INSTALL_DEV) : _T(URL_INSTALL);
wstring url_filename = L"DesktopEditors_";
url_filename += NS_Utils::IsWin64() ? _T("x64") : _T("x86");
url_filename += _T(".exe");
NS_Utils::Replace(url_or_path, _T("<file>"), url_filename);
}

Application app(hInst, lpCmdLine, nCmdShow);
Expand Down
34 changes: 4 additions & 30 deletions win-linux/extras/online-installer/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,6 @@
#include "../../src/defines.h"
#include "../../src/prop/defines_p.h"

#ifndef URL_INSTALL_X64
# define URL_INSTALL_X64 ""
#endif
#ifndef URL_INSTALL_X86
# define URL_INSTALL_X86 ""
#endif
#ifndef URL_INSTALL_X64_XP
# define URL_INSTALL_X64_XP ""
#endif
#ifndef URL_INSTALL_X86_XP
# define URL_INSTALL_X86_XP ""
#endif
#ifndef URL_INSTALL_X64_MSI
# define URL_INSTALL_X64_MSI ""
#endif
#ifndef URL_INSTALL_X86_MSI
# define URL_INSTALL_X86_MSI ""
#endif
#define _TR(str) Translator::tr(str).c_str()


Expand Down Expand Up @@ -390,16 +372,10 @@ void MainWindow::finishInstall(const std::wstring &app_path)
void MainWindow::startUpdate()
{
wstring tmp_path = NS_File::toNativeSeparators(NS_File::generateTmpFileName(L"." + m_package));
wstring url;
if (m_package == L"msi") {
url = (m_arch == L"x64") ? _T(URL_INSTALL_X64_MSI) : _T(URL_INSTALL_X86_MSI);
} else {
if (Utils::getWinVersion() <= Utils::WinVer::WinVista) {
url = (m_arch == L"x64") ? _T(URL_INSTALL_X64_XP) : _T(URL_INSTALL_X86_XP);
} else {
url = (m_arch == L"x64") ? _T(URL_INSTALL_X64) : _T(URL_INSTALL_X86);
}
}
wstring url = NS_Utils::cmdArgContains(_T("--appcast-dev-channel")) ? _T(URL_INSTALL_DEV) : _T(URL_INSTALL);
wstring url_filename = L"DesktopEditors_" + m_arch;
url_filename.append(L"." + m_package);
NS_Utils::Replace(url, _T("<file>"), url_filename);

CDownloader *dnl = startDownload(url, tmp_path, [=]() {
m_bar->pulse(true);
Expand Down Expand Up @@ -445,8 +421,6 @@ void MainWindow::startRepair()
wstring url = L"https://github.com/%1/%2/releases/download/%3/%4";
{
wstring url_filename = L"DesktopEditors_" + m_arch;
if (Utils::getWinVersion() <= Utils::WinVer::WinVista)
url_filename.append(L"_xp");
url_filename.append(L"." + m_package);

wstring url_ver = L"v" + m_ver;
Expand Down
26 changes: 26 additions & 0 deletions win-linux/extras/online-installer/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ static void RegQueryStringValue(HKEY rootKey, LPCWSTR subkey, REGSAM advFlags, L

namespace NS_Utils
{
std::vector<wstring> cmd_args;

void parseCmdArgs(int argc, wchar_t *argv[])
{
for (int i = 0; i < argc; i++)
cmd_args.push_back(argv[i]);
}

bool cmdArgContains(const wstring &param)
{
auto len = param.length();
return std::any_of(cmd_args.cbegin(), cmd_args.cend(), [&param, len](const wstring &arg) {
return arg.find(param) == 0 && (len == arg.length() || arg[len] == L'=' || arg[len] == L':' || arg[len] == L'|');
});
}

wstring cmdArgValue(const wstring &param)
{
auto len = param.length();
for (const auto &arg : cmd_args) {
if (arg.find(param) == 0 && len < arg.length() && (arg[len] == L'=' || arg[len] == L':' || arg[len] == L'|'))
return arg.substr(len + 1);
}
return L"";
}

wstring GetLastErrorAsString(DWORD _errID)
{
DWORD errID = _errID != 0 ? _errID : ::GetLastError();
Expand Down
3 changes: 3 additions & 0 deletions win-linux/extras/online-installer/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ using std::to_wstring;

namespace NS_Utils
{
void parseCmdArgs(int argc, wchar_t *argv[]);
bool cmdArgContains(const wstring &param);
wstring cmdArgValue(const wstring &param);
wstring GetLastErrorAsString(DWORD errID = 0);
void ShowMessage(wstring str, bool showError = false);
bool IsRtlLanguage(unsigned long lcid);
Expand Down

0 comments on commit b5beda7

Please sign in to comment.