void BackupWindow::MessageReceived(BMessage *msg) { switch (msg->what) { case kMsgDoBackup: DoBackup(fBackupView->GetTasks()); break; case kMsgUpdateSelection: fBackupView->RefreshTotal(); break; default: BWindow::MessageReceived(msg); } }
/** \fn DBUtil::BackupDB(QString&, bool) * \brief Requests a backup of the database. * * If the DatabaseBackupScript exists in the ShareDir, it will be executed. * All required database information will be made available as name=value * pairs in a temporary file whose filename will be passed to the backup * script. The script may parse this file to obtain the required information * to run a backup program, such as mysqldump or mysqlhotcopy. * * If the DatabaseBackupScript does not exist, a backup will be performed * using mysqldump directly. The database password will be passed in a * temporary file so it does not have to be specified on the command line. * * Care should be taken in calling this function. It has the potential to * corrupt in-progress recordings or interfere with playback. * * The disableRotation argument should be used only for automatic backups * when users could lose important backup files due to a failure loop--for * example, a DB upgrade failure and a distro start script that keeps * restarting mythbackend even when it exits with an error status. * * \param filename Used to return the name of the resulting backup file * \param disableRotation Disable backup rotation * \return MythDBBackupStatus indicating the result */ MythDBBackupStatus DBUtil::BackupDB(QString &filename, bool disableRotation) { filename = QString(); #ifdef USING_MINGW LOG(VB_GENERAL, LOG_CRIT, "Database backups disabled on Windows."); return kDB_Backup_Disabled; #endif if (gCoreContext->GetNumSetting("DisableAutomaticBackup", 0)) { LOG(VB_GENERAL, LOG_CRIT, "Database backups disabled. Skipping backup."); return kDB_Backup_Disabled; } if (IsNewDatabase()) { LOG(VB_GENERAL, LOG_CRIT, "New database detected. Skipping backup."); return kDB_Backup_Empty_DB; } QString backupScript = GetShareDir() + "mythconverg_backup.pl"; backupScript = gCoreContext->GetSetting("DatabaseBackupScript", backupScript); if (!QFile::exists(backupScript)) { LOG(VB_GENERAL, LOG_CRIT, QString("Database backup script does " "not exist: %1").arg(backupScript)); backupScript = QString::null; } bool result = false; MSqlQuery query(MSqlQuery::InitCon()); gCoreContext->SaveSettingOnHost("BackupDBLastRunStart", QDateTime::currentDateTime() .toString("yyyy-MM-dd hh:mm:ss"), NULL); if (!backupScript.isEmpty()) { result = DoBackup(backupScript, filename, disableRotation); if (!result) LOG(VB_GENERAL, LOG_CRIT, "Script-based database backup failed. " "Retrying with internal backup."); } if (!result) result = DoBackup(filename); gCoreContext->SaveSettingOnHost("BackupDBLastRunEnd", QDateTime::currentDateTime() .toString("yyyy-MM-dd hh:mm:ss"), NULL); if (query.isConnected()) { QString dbTag("BackupDB"); query.prepare("DELETE FROM housekeeping WHERE tag = :TAG ;"); query.bindValue(":TAG", dbTag); if (!query.exec()) MythDB::DBError("DBUtil::BackupDB", query); query.prepare("INSERT INTO housekeeping(tag,lastrun) " "values(:TAG ,now()) ;"); query.bindValue(":TAG", dbTag); if (!query.exec()) MythDB::DBError("DBUtil::BackupDB", query); } if (result) return kDB_Backup_Completed; return kDB_Backup_Failed; }
Application::Application(QObject* parent) : QObject(parent), tag_reader_client_(nullptr), database_(nullptr), album_cover_loader_(nullptr), playlist_backend_(nullptr), podcast_backend_(nullptr), appearance_(nullptr), cover_providers_(nullptr), task_manager_(nullptr), player_(nullptr), playlist_manager_(nullptr), current_art_loader_(nullptr), global_search_(nullptr), internet_model_(nullptr), library_(nullptr), device_manager_(nullptr), podcast_updater_(nullptr), podcast_deleter_(nullptr), podcast_downloader_(nullptr), gpodder_sync_(nullptr), moodbar_loader_(nullptr), moodbar_controller_(nullptr), network_remote_(nullptr), network_remote_helper_(nullptr), scrobbler_(nullptr) { tag_reader_client_ = new TagReaderClient(this); MoveToNewThread(tag_reader_client_); tag_reader_client_->Start(); database_ = new Database(this, this); MoveToNewThread(database_); album_cover_loader_ = new AlbumCoverLoader(this); MoveToNewThread(album_cover_loader_); playlist_backend_ = new PlaylistBackend(this, this); MoveToThread(playlist_backend_, database_->thread()); podcast_backend_ = new PodcastBackend(this, this); MoveToThread(podcast_backend_, database_->thread()); appearance_ = new Appearance(this); cover_providers_ = new CoverProviders(this); task_manager_ = new TaskManager(this); player_ = new Player(this, this); playlist_manager_ = new PlaylistManager(this, this); current_art_loader_ = new CurrentArtLoader(this, this); global_search_ = new GlobalSearch(this, this); internet_model_ = new InternetModel(this, this); library_ = new Library(this, this); device_manager_ = new DeviceManager(this, this); podcast_updater_ = new PodcastUpdater(this, this); podcast_deleter_ = new PodcastDeleter(this, this); MoveToNewThread(podcast_deleter_); podcast_downloader_ = new PodcastDownloader(this, this); gpodder_sync_ = new GPodderSync(this, this); #ifdef HAVE_MOODBAR moodbar_loader_ = new MoodbarLoader(this, this); moodbar_controller_ = new MoodbarController(this, this); #endif // Network Remote network_remote_ = new NetworkRemote(this); MoveToNewThread(network_remote_); // This must be before libraray_->Init(); // In the constructor the helper waits for the signal // PlaylistManagerInitialized // to start the remote. Without the playlist manager clementine can // crash when a client connects before the manager is initialized! network_remote_helper_ = new NetworkRemoteHelper(this); #ifdef HAVE_LIBLASTFM scrobbler_ = new LastFMService(this, this); #endif // HAVE_LIBLASTFM library_->Init(); DoInAMinuteOrSo(database_, SLOT(DoBackup())); }
//-------------------------------------------------------------------------------- int Parse(CStdioFile& fIn, CFile& fOut, CFile& fOutBkup) { char temp[4096]; char temp2[4096]; char sName[512]; char* pBuf; CTokenMaster* pMaster = NULL; sName[0] = 0; bool bRv = false; for(;;) { pBuf = temp; if(! fIn.ReadString(pBuf, 4096)) break; while(isspace(*pBuf) && *pBuf) pBuf++; if(! *pBuf) continue; if(*pBuf == ';') continue; else { // remove all non esential characters from the string int i = 0; for(char* pBuf2 = pBuf; *pBuf2; pBuf2++) { // if(isalnum(*pBuf2) || *pBuf2 == ',' || *pBuf2 == '=') if(isprint(*pBuf2)) temp2[i++] = *pBuf2; } if(i == 0) continue; temp2[i] = 0; pBuf = temp2; } printf("%s\n", pBuf); char* pBreak = strchr(pBuf, '='); if(pBreak == NULL) { printf("syntax error ^^^^^^^ (= missing)\n"); continue; } *pBreak = 0; if(*pBuf == 0) continue; LPCTSTR pKeywords[] = {"token", "count", "max", "bits", "name", "serial", "p3", "processor", "dongle", "email", "expires", "extra", "backup", "monitor", "parent" }; enum { IDTOKEN, IDCOUNT, IDMAX, IDBITS, IDNAME, IDSERIAL, IDP3, IDPROCESSOR, IDDONGLE, IDEMAIL, IDEXPIRES, IDEXTRA, IDBACKUP, IDMONITOR, IDPARENT, NCOUNT }; const int nCount = sizeof(pKeywords) / sizeof(LPCTSTR); assert(nCount == NCOUNT); for(int i = 0; i < nCount; i++) { if(strcmp(pBuf, pKeywords[i]) == 0) break; } switch(i) { case IDTOKEN: bRv = DoToken(pBreak+1, pMaster); break; case IDCOUNT: bRv = DoCount(pBreak+1, pMaster); break; case IDMAX: bRv = DoMax(pBreak+1, pMaster); break; case IDBITS: bRv = DoBits(pBreak+1, pMaster); break; case IDNAME: bRv = DoName(pBreak+1, pMaster); break; case IDSERIAL: case IDP3: case IDPROCESSOR: bRv = DoP3Serial(pBreak+1, pMaster); break; case IDDONGLE: bRv = DoDongle(pBreak+1, pMaster); break; case IDEMAIL: bRv = DoEmail(pBreak+1, pMaster); break; case IDEXPIRES: bRv = DoExpires(pBreak+1, pMaster); break; case IDEXTRA: bRv = DoExtra(pBreak+1, pMaster); break; case IDBACKUP: bRv = DoBackup(pBreak+1, pMaster); break; case IDMONITOR: bRv = DoMonitor(pBreak+1, pMaster); break; case IDPARENT: bRv = DoParent(pBreak+1, pMaster); break; default: printf("syntax error ^^^^^^^ (unknown keyword)\n"); bRv = false; continue; } } if(! bRv) return -1; if(! WriteFile(fOut, fOutBkup)) return -1; return 0; }
ApplicationImpl(Application* app) : tag_reader_client_([=]() { TagReaderClient* client = new TagReaderClient(app); app->MoveToNewThread(client); client->Start(); return client; }), database_([=]() { Database* db = new Database(app, app); app->MoveToNewThread(db); DoInAMinuteOrSo(db, SLOT(DoBackup())); return db; }), album_cover_loader_([=]() { AlbumCoverLoader* loader = new AlbumCoverLoader(app); app->MoveToNewThread(loader); return loader; }), playlist_backend_([=]() { PlaylistBackend* backend = new PlaylistBackend(app, app); app->MoveToThread(backend, database_->thread()); return backend; }), podcast_backend_([=]() { PodcastBackend* backend = new PodcastBackend(app, app); app->MoveToThread(backend, database_->thread()); return backend; }), appearance_([=]() { return new Appearance(app); }), cover_providers_([=]() { CoverProviders* cover_providers = new CoverProviders(app); // Initialize the repository of cover providers. cover_providers->AddProvider(new MusicbrainzCoverProvider); #ifdef HAVE_LIBLASTFM cover_providers->AddProvider(new LastFmCoverProvider(app)); #endif return cover_providers; }), task_manager_([=]() { return new TaskManager(app); }), player_([=]() { return new Player(app, app); }), playlist_manager_([=]() { return new PlaylistManager(app); }), current_art_loader_([=]() { return new CurrentArtLoader(app, app); }), global_search_([=]() { return new GlobalSearch(app, app); }), internet_model_([=]() { return new InternetModel(app, app); }), library_([=]() { return new Library(app, app); }), device_manager_([=]() { return new DeviceManager(app, app); }), podcast_updater_([=]() { return new PodcastUpdater(app, app); }), podcast_deleter_([=]() { PodcastDeleter* deleter = new PodcastDeleter(app, app); app->MoveToNewThread(deleter); return deleter; }), podcast_downloader_([=]() { return new PodcastDownloader(app, app); }), gpodder_sync_([=]() { return new GPodderSync(app, app); }), moodbar_loader_([=]() { #ifdef HAVE_MOODBAR return new MoodbarLoader(app, app); #else return nullptr; #endif }), moodbar_controller_([=]() { #ifdef HAVE_MOODBAR return new MoodbarController(app, app); #else return nullptr; #endif }), network_remote_([=]() { NetworkRemote* remote = new NetworkRemote(app); app->MoveToNewThread(remote); return remote; }), network_remote_helper_([=]() { return new NetworkRemoteHelper(app); }), scrobbler_([=]() { #ifdef HAVE_LIBLASTFM return new LastFMService(app, app); #else return nullptr; #endif }) { }