| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2018 Robert Kausch <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation, either version 2 of |
| 7 | * the License, or (at your option) any later version. |
| 8 | * |
| 9 | * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
| 10 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 11 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ |
| 12 | |
| 13 | #include <jobs/other/checkforupdates.h> |
| 14 | |
| 15 | #include <freac.h> |
| 16 | #include <config.h> |
| 17 | #include <dllinterfaces.h> |
| 18 | |
| 19 | using namespace smooth::GUI::Dialogs; |
| 20 | |
| 21 | freac::JobCheckForUpdates::JobCheckForUpdates(Bool iStartup) |
| 22 | { |
| 23 | startup = iStartup; |
| 24 | } |
| 25 | |
| 26 | freac::JobCheckForUpdates::~JobCheckForUpdates() |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | Error freac::JobCheckForUpdates::Perform() |
| 31 | { |
| 32 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 33 | |
| 34 | i18n->SetContext("Jobs::Update"); |
| 35 | |
| 36 | if (!Config::Get()->enable_eUpdate) return Success(); |
| 37 | |
| 38 | SetText(i18n->AddEllipsis(i18n->TranslateString("Preparing update check"))); |
| 39 | |
| 40 | /* Do not check for updates on first startup. |
| 41 | */ |
| 42 | if (startup && configuration->GetIntValue(Config::CategorySettingsID, Config::SettingsStartCountID, Config::SettingsStartCountDefault) == 1) |
| 43 | { |
| 44 | return Success(); |
| 45 | } |
| 46 | |
| 47 | /* Ask whether to check for updates on second startup. |
| 48 | */ |
| 49 | if (startup && configuration->GetIntValue(Config::CategorySettingsID, Config::SettingsStartCountID, Config::SettingsStartCountDefault) == 2 && |
| 50 | !configuration->GetIntValue(Config::CategorySettingsID, Config::SettingsUpdatesCheckedID, Config::SettingsUpdatesCheckedDefault)) |
| 51 | { |
| 52 | if (QuickMessage(i18n->TranslateString("%1 can perform an automatic check for online\nprogram updates at startup.\n\nWould you like %1 to look for updates at startup?", "Updates").Replace("%1", freac::appName), String(freac::appName).Append(" easyUpdate"), Message::Buttons::YesNo, Message::Icon::Question) == Message::Button::No) |
| 53 | { |
| 54 | BoCA::Config *config = BoCA::Config::Get(); |
| 55 | |
| 56 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsCheckForUpdatesID, False); |
| 57 | |
| 58 | return Success(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /* Create update context and check for updates. |
| 63 | */ |
| 64 | #ifdef __WIN32__ |
| 65 | Void *context = ex_eUpdate_CreateUpdateContext(freac::appLongName, freac::version, freac::updatePath); |
| 66 | |
| 67 | if (configuration->configDir != NIL) ex_eUpdate_SetConfigFile(context, String(configuration->configDir).Append("eUpdate.xml")); |
| 68 | |
| 69 | String language = configuration->GetStringValue(Config::CategorySettingsID, Config::SettingsLanguageID, Config::SettingsLanguageDefault); |
| 70 | |
| 71 | if (language != "internal") |
| 72 | { |
| 73 | String langID; |
| 74 | |
| 75 | for (Int i = language.Find("_") + 1; i < language.Length(); i++) langID[i - language.Find("_") - 1] = language[i]; |
| 76 | |
| 77 | if (!ex_eUpdate_SetLanguage(context, String("eupdate_").Append(langID))) ex_eUpdate_SetLanguage(context, String("internal")); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | ex_eUpdate_SetLanguage(context, String("internal")); |
| 82 | } |
| 83 | |
| 84 | i18n->ActivateLanguage(language); |
| 85 | i18n->SetContext("Jobs::Update"); |
| 86 | |
| 87 | SetText(i18n->AddEllipsis(i18n->TranslateString("Contacting update server"))); |
| 88 | SetProgress(100); |
| 89 | |
| 90 | Bool checkUpdates = configuration->GetIntValue(Config::CategorySettingsID, Config::SettingsCheckForUpdatesID, Config::SettingsCheckForUpdatesDefault); |
| 91 | |
| 92 | if (ex_eUpdate_CheckForNewUpdates(context, !startup) > 0) |
| 93 | { |
| 94 | SetText(i18n->TranslateString("Updates found")); |
| 95 | SetProgress(1000); |
| 96 | |
| 97 | MessageDlg msgBox(i18n->TranslateString("There are new updates for %1 available online!\nWould you like to see a list of available updates now?", "Updates").Replace("%1", freac::appName), String(freac::appName).Append(" easyUpdate"), Message::Buttons::YesNo, Message::Icon::Question, i18n->TranslateString("Check for updates at startup", "Updates"), &checkUpdates); |
| 98 | |
| 99 | msgBox.ShowDialog(); |
| 100 | |
| 101 | if (msgBox.GetButtonCode() == Message::Button::Yes) |
| 102 | { |
| 103 | BoCA::Config *config = BoCA::Config::Get(); |
| 104 | |
| 105 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsCheckForUpdatesID, checkUpdates); |
| 106 | config->SaveSettings(); |
| 107 | |
| 108 | ex_eUpdate_AutomaticUpdate(context); |
| 109 | } |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | SetText(i18n->TranslateString("No updates found")); |
| 114 | SetProgress(1000); |
| 115 | |
| 116 | if (!startup) |
| 117 | { |
| 118 | MessageDlg msgBox(i18n->TranslateString("There are no updates available at the moment!", "Updates"), String(freac::appName).Append(" easyUpdate"), Message::Buttons::Ok, Message::Icon::Information, i18n->TranslateString("Check for updates at startup", "Updates"), &checkUpdates); |
| 119 | |
| 120 | msgBox.ShowDialog(); |
| 121 | } |
| 122 | else if (configuration->GetIntValue(Config::CategorySettingsID, Config::SettingsStartCountID, Config::SettingsStartCountDefault) == 2) |
| 123 | { |
| 124 | QuickMessage(i18n->TranslateString("There are no updates available at the moment!", "Updates"), String(freac::appName).Append(" easyUpdate"), Message::Buttons::Ok, Message::Icon::Information); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | BoCA::Config *config = BoCA::Config::Get(); |
| 129 | |
| 130 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsCheckForUpdatesID, checkUpdates); |
| 131 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsUpdatesCheckedID, True); |
| 132 | |
| 133 | ex_eUpdate_FreeUpdateContext(context); |
| 134 | #endif |
| 135 | |
| 136 | return Success(); |
| 137 | } |