| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2026 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 <smooth.h> |
| 14 | |
| 15 | #include <boca.h> |
| 16 | #include <freac.h> |
| 17 | |
| 18 | #include <config.h> |
| 19 | #include <utilities.h> |
| 20 | #include <dllinterfaces.h> |
| 21 | |
| 22 | #include <jobs/jobmanager.h> |
| 23 | #include <cddb/cddbcache.h> |
| 24 | |
| 25 | #include <engine/component.h> |
| 26 | |
| 27 | freac::freac *freac::freac::instance = NIL; |
| 28 | |
| 29 | /* General application information and fixed settings. |
| 30 | */ |
| 31 | #ifndef BUILD_VIDEO_DOWNLOADER |
| 32 | String freac::freac::appName = "fre:ac"; |
| 33 | String freac::freac::appLongName = "fre:ac - free audio converter"; |
| 34 | #else |
| 35 | String freac::freac::appName = "vi:ldr"; |
| 36 | String freac::freac::appLongName = "vi:ldr - free video downloader"; |
| 37 | #endif |
| 38 | |
| 39 | #ifdef FREAC_VERSION |
| 40 | String freac::freac::version = FREAC_VERSION; |
| 41 | #else |
| 42 | # ifdef FREAC_DATE |
| 43 | String freac::freac::version = "v1.1.7 (" FREAC_DATE ")"; |
| 44 | # else |
| 45 | String freac::freac::version = "v1.1.7"; |
| 46 | # endif |
| 47 | #endif |
| 48 | |
| 49 | #if defined __i386__ || defined _M_IX86 |
| 50 | String freac::freac::architecture = "x86"; |
| 51 | #elif defined __x86_64__ || defined _M_AMD64 |
| 52 | String freac::freac::architecture = "x86-64"; |
| 53 | #elif defined __arm__ || defined _M_ARM |
| 54 | String freac::freac::architecture = "ARM"; |
| 55 | #elif defined __aarch64__ || defined _M_ARM64 |
| 56 | String freac::freac::architecture = "ARM64"; |
| 57 | #elif defined __mips__ |
| 58 | String freac::freac::architecture = "MIPS"; |
| 59 | #elif defined __ppc64__ || defined __powerpc64__ |
| 60 | String freac::freac::architecture = "PPC64"; |
| 61 | #elif defined __ppc__ || defined __powerpc__ |
| 62 | String freac::freac::architecture = "PPC"; |
| 63 | #elif defined __riscv |
| 64 | String freac::freac::architecture = "RISC-V"; |
| 65 | #else |
| 66 | String freac::freac::architecture = "unknown"; |
| 67 | #endif |
| 68 | |
| 69 | String freac::freac::shortVersion = "v1.1.7"; |
| 70 | String freac::freac::cddbVersion = "v1.1.7"; // CDDB version may not contain spaces |
| 71 | String freac::freac::cddbMode = "submit"; |
| 72 | |
| 73 | String freac::freac::copyright = "Copyright (C) 2001-2026 Robert Kausch"; |
| 74 | |
| 75 | String freac::freac::website = "https://www.freac.org/"; |
| 76 | |
| 77 | String freac::freac::issueTracker = "https://github.com/enzo1982/freac/labels/bug"; |
| 78 | String freac::freac::featureTracker = "https://github.com/enzo1982/freac/labels/enhancement"; |
| 79 | |
| 80 | #if defined __i386__ |
| 81 | String freac::freac::updatePath = "https://www.freac.org/eUpdate/eUpdate.xml"; |
| 82 | #else |
| 83 | String freac::freac::updatePath = String("https://www.freac.org/eUpdate/eUpdate-").Append(freac::freac::architecture).Append(".xml"); |
| 84 | #endif |
| 85 | |
| 86 | /* Use these settings for debugging. |
| 87 | */ |
| 88 | //String freac::freac::cddbMode = "test"; |
| 89 | //String freac::freac::updatePath = "file://eUpdate/eUpdate.xml"; |
| 90 | |
| 91 | freac::freac::freac() : Application(appName) |
| 92 | { |
| 93 | /* Init BoCA library. |
| 94 | */ |
| 95 | BoCA::Init("fre:ac"); |
| 96 | |
| 97 | /* Setup debug protocol. |
| 98 | */ |
| 99 | BoCA::Protocol *debug = BoCA::Protocol::Get("Debug output"); |
| 100 | |
| 101 | debug->Write("Starting fre:ac..."); |
| 102 | |
| 103 | instance = this; |
| 104 | |
| 105 | /* Load configuration. |
| 106 | */ |
| 107 | debug->Write(" Loading config..."); |
| 108 | |
| 109 | BoCA::Config *config = BoCA::Config::Get(); |
| 110 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 111 | |
| 112 | currentConfig = Config::Get(); |
| 113 | |
| 114 | /* Set interface language. |
| 115 | */ |
| 116 | String language = config->GetStringValue(Config::CategorySettingsID, Config::SettingsLanguageID, Config::SettingsLanguageDefault); |
| 117 | |
| 118 | if (language != NIL) i18n->ActivateLanguage(language); |
| 119 | else i18n->SelectUserDefaultLanguage(); |
| 120 | |
| 121 | config->SetStringValue(Config::CategorySettingsID, Config::SettingsLanguageID, i18n->GetActiveLanguageID()); |
| 122 | |
| 123 | /* Increment start count. |
| 124 | */ |
| 125 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsStartCountID, config->GetIntValue(Config::CategorySettingsID, Config::SettingsStartCountID, Config::SettingsStartCountDefault) + 1); |
| 126 | |
| 127 | /* Set process priority. |
| 128 | */ |
| 129 | Utilities::SetProcessPriority(); |
| 130 | |
| 131 | /* Set default comment unless already set. |
| 132 | */ |
| 133 | config->SetStringValue(Config::CategoryTagsID, Config::TagsDefaultCommentID, config->GetStringValue(Config::CategoryTagsID, Config::TagsDefaultCommentID, String(appLongName).Append(" <").Append(website).Append(">"))); |
| 134 | |
| 135 | /* Connect version information to BoCA callbacks. |
| 136 | */ |
| 137 | BoCA::Application::Get()->getScreenName.Connect(appLongName); |
| 138 | |
| 139 | BoCA::Application::Get()->getClientName.Connect(appName); |
| 140 | BoCA::Application::Get()->getClientVersion.Connect(version); |
| 141 | |
| 142 | /* Start job manager. |
| 143 | */ |
| 144 | debug->Write(" Starting job manager..."); |
| 145 | |
| 146 | JobManager::Start(); |
| 147 | |
| 148 | debug->Write(" Loading online updater..."); |
| 149 | |
| 150 | if (DLLInterfaces::LoadEUpdateDLL() == False) currentConfig->enable_eUpdate = False; |
| 151 | else currentConfig->enable_eUpdate = True; |
| 152 | |
| 153 | if (!currentConfig->enable_eUpdate) debug->Write(" Online updater not found."); |
| 154 | } |
| 155 | |
| 156 | freac::freac::~freac() |
| 157 | { |
| 158 | BoCA::Protocol *debug = BoCA::Protocol::Get("Debug output"); |
| 159 | |
| 160 | /* Quit the job manager. |
| 161 | */ |
| 162 | debug->Write(" Stopping job manager..."); |
| 163 | |
| 164 | JobManager::Quit(); |
| 165 | |
| 166 | debug->Write(" Cleaning up..."); |
| 167 | |
| 168 | /* Free conversion locks. |
| 169 | */ |
| 170 | Component::FreeLockObjects(); |
| 171 | |
| 172 | /* Free the CDDB cache. |
| 173 | */ |
| 174 | CDDBCache::Free(); |
| 175 | |
| 176 | /* Free easyUpdate library. |
| 177 | */ |
| 178 | if (currentConfig->enable_eUpdate) DLLInterfaces::FreeEUpdateDLL(); |
| 179 | |
| 180 | /* Cleanup deletable objects before deleting encoder and translator. |
| 181 | */ |
| 182 | Object::ObjectCleanup(); |
| 183 | |
| 184 | Config::Free(); |
| 185 | |
| 186 | debug->Write("Leaving fre:ac..."); |
| 187 | |
| 188 | BoCA::Protocol::Free(); |
| 189 | |
| 190 | /* Free BoCA library. |
| 191 | */ |
| 192 | BoCA::Free(); |
| 193 | } |