bool COPKGManager::checkUpdates(const std::string & package_name, bool show_progress) { if (!hasOpkgSupport()) return false; doUpdate(); bool ret = false; size_t i = 0; CProgressWindow status; status.showHeader(false); if (show_progress){ status.paint(); status.showStatusMessageUTF(g_Locale->getText(LOCALE_OPKG_UPDATE_READING_LISTS)); status.showStatus(25); /* after do_update, we have actually done the hardest work already */ } getPkgData(OM_LIST); if (show_progress) status.showStatus(50); getPkgData(OM_LIST_UPGRADEABLE); if (show_progress) status.showStatus(75); for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it){ dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update check for...%s\n", __func__, __LINE__, it->second.name.c_str()); if (show_progress){ /* showing the names only makes things *much* slower... status.showStatusMessageUTF(it->second.name); */ status.showStatus(75 + 25*i / pkg_map.size()); } if (it->second.upgradable){ dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update packages available for...%s\n", __func__, __LINE__, it->second.name.c_str()); if (!package_name.empty() && package_name == it->second.name){ ret = true; break; }else ret = true; } i++; } if (show_progress){ status.showGlobalStatus(100); status.showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); // UTF-8 status.hide(); } #if 0 pkg_map.clear(); #endif return ret; }
void CTestMenu::testCProgressWindow() { CProgressWindow * progress; progress = new CProgressWindow(); progress->setTitle("CProgressWindow"); progress->exec(NULL, ""); progress->showStatusMessageUTF("testing CProgressWindow"); progress->showGlobalStatus(0); usleep(1000000); progress->showGlobalStatus(10); usleep(1000000); progress->showGlobalStatus(20); usleep(1000000); progress->showGlobalStatus(30); usleep(1000000); progress->showGlobalStatus(40); usleep(1000000); progress->showGlobalStatus(50); usleep(1000000); progress->showGlobalStatus(60); usleep(1000000); progress->showGlobalStatus(70); usleep(1000000); progress->showGlobalStatus(80); usleep(1000000); progress->showGlobalStatus(90); usleep(1000000); progress->showGlobalStatus(100); usleep(1000000); progress->hide(); delete progress; progress = NULL; }
int CHDDChkExec::exec(CMenuTarget* parent, const std::string& key) { char cmd[100]; CHintBox * hintbox; int res; char src[128], dst[128]; FILE * f; CProgressWindow * progress; int oldpass = 0, pass, step, total; int percent = 0, opercent = 0; sprintf(src, "/dev/%s1", key.c_str()); sprintf(dst, "/media/%s1", key.c_str()); printf("CHDDChkExec: key %s\n", key.c_str()); bool srun = system("killall -9 smbd"); //res = check_and_umount(dst); res = check_and_umount(src, dst); printf("CHDDChkExec: umount res %d\n", res); if(res) { hintbox = new CHintBox(LOCALE_HDD_CHECK, g_Locale->getText(LOCALE_HDD_UMOUNT_WARN)); hintbox->paint(); sleep(2); delete hintbox; return menu_return::RETURN_REPAINT; } switch(g_settings.hdd_fs) { case 0: sprintf(cmd, "/sbin/fsck.ext3 -C 1 -f -y %s", src); break; case 1: sprintf(cmd, "/sbin/fsck.ext2 -C 1 -f -y %s", src); break; case 2: sprintf(cmd, "/sbin/reiserfsck --fix-fixable %s", src); break; default: return 0; } printf("CHDDChkExec: Executing %s\n", cmd); f=popen(cmd, "r"); if(!f) { hintbox = new CHintBox(LOCALE_HDD_CHECK, g_Locale->getText(LOCALE_HDD_CHECK_FAILED)); hintbox->paint(); sleep(2); delete hintbox; goto ret1; } progress = new CProgressWindow(); progress->setTitle(LOCALE_HDD_CHECK); progress->exec(NULL,""); char buf[256]; while(fgets(buf, 255, f) != NULL) { if(isdigit(buf[0])) { sscanf(buf, "%d %d %d\n", &pass, &step, &total); if(total == 0) total = 1; if(oldpass != pass) { oldpass = pass; progress->showGlobalStatus(pass > 0 ? (pass-1)*20: 0); } percent = (step * 100) / total; if(opercent != percent) { opercent = percent; //printf("CHDDChkExec: pass %d : %d\n", pass, percent); progress->showLocalStatus(percent); } } else if(!strncmp(buf, "Pass", 4)) progress->showStatusMessageUTF(buf); } //printf("CHDDChkExec: %s\n", buf); pclose(f); progress->showGlobalStatus(100); progress->showStatusMessageUTF(buf); sleep(2); progress->hide(); delete progress; ret1: switch(g_settings.hdd_fs) { case 0: res = mount(src, dst, "ext3", 0, NULL); break; case 1: res = mount(src, dst, "ext2", 0, NULL); break; case 2: res = mount(src, dst, "reiserfs", 0, NULL); break; default: break; } printf("CHDDChkExec: mount res %d\n", res); if(!srun) system("smbd"); return menu_return::RETURN_REPAINT; }
int CHDDFmtExec::exec(CMenuTarget* parent, const std::string& key) { char cmd[100]; CHintBox * hintbox; int res; FILE * f; char src[128], dst[128]; CProgressWindow * progress; bool idone; sprintf(src, "/dev/%s1", key.c_str()); sprintf(dst, "/media/%s1", key.c_str()); printf("CHDDFmtExec: key %s\n", key.c_str()); res = ShowMsgUTF ( LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_WARN), CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo ); if(res != CMessageBox::mbrYes) return 0; bool srun = system("killall -9 smbd"); //res = check_and_umount(dst); res = check_and_umount(src, dst); printf("CHDDFmtExec: umount res %d\n", res); if(res) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_UMOUNT_WARN)); hintbox->paint(); sleep(2); delete hintbox; goto _return; } f = fopen("/proc/sys/kernel/hotplug", "w"); if(f) { fprintf(f, "none\n"); fclose(f); } progress = new CProgressWindow(); progress->setTitle(LOCALE_HDD_FORMAT); progress->exec(NULL,""); progress->showStatusMessageUTF("Executing fdisk"); progress->showGlobalStatus(0); sprintf(cmd, "/sbin/sfdisk -f -uM /dev/%s", key.c_str()); printf("CHDDFmtExec: executing %s\n", cmd); f=popen(cmd, "w"); if (!f) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_FAILED)); hintbox->paint(); sleep(2); delete hintbox; goto _remount; } fprintf(f, "0,\n;\n;\n;\ny\n"); pclose(f); //sleep(1); switch(g_settings.hdd_fs) { case 0: sprintf(cmd, "/sbin/mkfs.ext3 -L RECORD -T largefile -j -m0 %s", src); break; case 1: sprintf(cmd, "/sbin/mkfs.ext2 -L RECORD -T largefile -m0 %s", src); break; case 2: sprintf(cmd, "/sbin/mkreiserfs -f -f %s", src); break; default: return 0; } printf("CHDDFmtExec: executing %s\n", cmd); f=popen(cmd, "r"); if (!f) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_FAILED)); hintbox->paint(); sleep(2); delete hintbox; goto _remount; } char buf[256]; idone = false; while(fgets(buf, 255, f) != NULL) { printf("%s", buf); if(!idone && strncmp(buf, "Writing inode", 13)) { idone = true; buf[21] = 0; progress->showGlobalStatus(20); progress->showStatusMessageUTF(buf); } else if(strncmp(buf, "Creating", 8)) { progress->showGlobalStatus(40); progress->showStatusMessageUTF(buf); } else if(strncmp(buf, "Writing superblocks", 19)) { progress->showGlobalStatus(60); progress->showStatusMessageUTF(buf); } } pclose(f); progress->showGlobalStatus(100); sleep(2); sprintf(cmd, "/sbin/tune2fs -r 0 -c 0 -i 0 %s", src); printf("CHDDFmtExec: executing %s\n", cmd); system(cmd); _remount: progress->hide(); delete progress; switch(g_settings.hdd_fs) { case 0: res = mount(src, dst, "ext3", 0, NULL); break; case 1: res = mount(src, dst, "ext2", 0, NULL); break; case 2: res = mount(src, dst, "reiserfs", 0, NULL); break; default: break; } f = fopen("/proc/sys/kernel/hotplug", "w"); if(f) { fprintf(f, "/sbin/hotplug\n"); fclose(f); } if(!res) { sprintf(cmd, "%s/movies", dst); safe_mkdir((char *) cmd); sprintf(cmd, "%s/pictures", dst); safe_mkdir((char *) cmd); sprintf(cmd, "%s/epg", dst); safe_mkdir((char *) cmd); sprintf(cmd, "%s/music", dst); safe_mkdir((char *) cmd); sync(); } _return: if(!srun) system("smbd"); return menu_return::RETURN_REPAINT; }
int CHDDFmtExec::exec(CMenuTarget* /*parent*/, const std::string& key) { char cmd[100]; char cmd2[100]; CHintBox * hintbox; int res; FILE * f; char src[128], dst[128]; CProgressWindow * progress; snprintf(src, sizeof(src), "/dev/%s1", key.c_str()); snprintf(dst, sizeof(dst), "/media/%s1", key.c_str()); printf("CHDDFmtExec: key %s\n", key.c_str()); res = ShowMsg ( LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_WARN), CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo ); if(res != CMessageBox::mbrYes) return 0; bool srun = my_system(3, "killall", "-9", "smbd"); //res = check_and_umount(dst); res = check_and_umount(src, dst); printf("CHDDFmtExec: umount res %d\n", res); if(res) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_UMOUNT_WARN)); hintbox->paint(); sleep(2); delete hintbox; goto _return; } f = fopen("/proc/sys/kernel/hotplug", "w"); if(f) { fprintf(f, "none\n"); fclose(f); } progress = new CProgressWindow(); progress->setTitle(LOCALE_HDD_FORMAT); progress->exec(NULL,""); progress->showStatusMessageUTF("Executing fdisk"); progress->showGlobalStatus(0); if (access("/sbin/sfdisk", X_OK) == 0) { snprintf(cmd, sizeof(cmd), "/sbin/sfdisk -f -uM /dev/%s", key.c_str()); strcpy(cmd2, "0,\n;\n;\n;\ny\n"); } else { snprintf(cmd, sizeof(cmd), "/sbin/fdisk /dev/%s", key.c_str()); strcpy(cmd2, "o\nn\np\n1\n\n\nw\n"); } printf("CHDDFmtExec: executing %s\n", cmd); f=popen(cmd, "w"); if (!f) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_FAILED)); hintbox->paint(); sleep(2); delete hintbox; goto _remount; } fprintf(f, "%s", cmd2); pclose(f); //sleep(1); switch(g_settings.hdd_fs) { case 0: snprintf(cmd, sizeof(cmd), "/sbin/mkfs.ext3 -T largefile -m0 %s", src); break; case 1: snprintf(cmd, sizeof(cmd), "/sbin/mkreiserfs -f -f %s", src); break; default: return 0; } printf("CHDDFmtExec: executing %s\n", cmd); f=popen(cmd, "r"); if (!f) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_FAILED)); hintbox->paint(); sleep(2); delete hintbox; goto _remount; } char buf[256]; setbuf(f, NULL); int n, t, in, pos, stage; pos = 0; stage = 0; while (true) { in = fgetc(f); if (in == EOF) break; buf[pos] = (char)in; pos++; buf[pos] = 0; if (in == '\b' || in == '\n') pos = 0; /* start a new line */ //printf("%s", buf); switch (stage) { case 0: if (strcmp(buf, "Writing inode tables:") == 0) { stage++; progress->showGlobalStatus(20); progress->showStatusMessageUTF(buf); } break; case 1: if (in == '\b' && sscanf(buf, "%d/%d\b", &n, &t) == 2) { int percent = 100 * n / t; progress->showLocalStatus(percent); progress->showGlobalStatus(20 + percent / 5); } if (strstr(buf, "done")) { stage++; pos = 0; } break; case 2: if (strstr(buf, "blocks):") && sscanf(buf, "Creating journal (%d blocks):", &n) == 1) { progress->showLocalStatus(0); progress->showGlobalStatus(60); progress->showStatusMessageUTF(buf); pos = 0; } if (strstr(buf, "done")) { stage++; pos = 0; } break; case 3: if (strcmp(buf, "Writing superblocks and filesystem accounting information:") == 0) { progress->showGlobalStatus(80); progress->showStatusMessageUTF(buf); pos = 0; } break; default: // printf("unknown stage! %d \n\t", stage); break; } } progress->showLocalStatus(100); pclose(f); progress->showGlobalStatus(100); sleep(2); printf("CHDDFmtExec: executing %s %s\n","/sbin/tune2fs -r 0 -c 0 -i 0", src); my_system(8, "/sbin/tune2fs", "-r", "0", "-c", "0", "-i", "0", src); _remount: progress->hide(); delete progress; switch(g_settings.hdd_fs) { case 0: safe_mkdir(dst); res = mount(src, dst, "ext3", 0, NULL); break; case 1: safe_mkdir(dst); res = mount(src, dst, "reiserfs", 0, NULL); break; default: break; } f = fopen("/proc/sys/kernel/hotplug", "w"); if(f) { #ifdef ASSUME_MDEV fprintf(f, "/sbin/mdev\n"); #else fprintf(f, "/sbin/hotplug\n"); #endif fclose(f); } if(!res) { snprintf(cmd, sizeof(cmd), "%s/movies", dst); safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/pictures", dst); safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/epg", dst); safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/music", dst); safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/logos", dst); safe_mkdir(cmd); snprintf(cmd, sizeof(cmd), "%s/plugins", dst); safe_mkdir(cmd); sync(); } _return: if (!srun) my_system(1, "smbd"); return menu_return::RETURN_REPAINT; }
int CHDDFmtExec::exec(CMenuTarget* /*parent*/, const std::string& key) { char cmd[100]; char cmd2[100]; CHintBox * hintbox; int res; FILE * f; char src[128], dst[128]; CProgressWindow * progress; snprintf(src, sizeof(src), "/dev/%s1", key.c_str()); snprintf(dst, sizeof(dst), "/media/%s1", key.c_str()); printf("CHDDFmtExec: key %s\n", key.c_str()); res = ShowMsgUTF ( LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_WARN), CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo ); if(res != CMessageBox::mbrYes) return 0; bool srun = system("killall -9 smbd"); //res = check_and_umount(dst); res = check_and_umount(src, dst); printf("CHDDFmtExec: umount res %d\n", res); if(res) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_UMOUNT_WARN)); hintbox->paint(); sleep(2); delete hintbox; goto _return; } f = fopen("/proc/sys/kernel/hotplug", "w"); if(f) { fprintf(f, "none\n"); fclose(f); } progress = new CProgressWindow(); progress->setTitle(LOCALE_HDD_FORMAT); progress->exec(NULL,""); progress->showStatusMessageUTF("Executing fdisk"); progress->showGlobalStatus(0); if (access("/sbin/sfdisk", X_OK) == 0) { snprintf(cmd, sizeof(cmd), "/sbin/sfdisk -f -uM /dev/%s", key.c_str()); strcpy(cmd2, "0,\n;\n;\n;\ny\n"); } else { snprintf(cmd, sizeof(cmd), "/sbin/fdisk /dev/%s", key.c_str()); strcpy(cmd2, "o\nn\np\n1\n\n\nw\n"); } printf("CHDDFmtExec: executing %s\n", cmd); f=popen(cmd, "w"); if (!f) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_FAILED)); hintbox->paint(); sleep(2); delete hintbox; goto _remount; } fprintf(f, "%s", cmd2); pclose(f); //sleep(1); switch(g_settings.hdd_fs) { case 0: snprintf(cmd, sizeof(cmd), "/sbin/mkfs.ext3 -T largefile -m0 %s", src); break; case 1: snprintf(cmd, sizeof(cmd), "/sbin/mkreiserfs -f -f %s", src); break; default: return 0; } printf("CHDDFmtExec: executing %s\n", cmd); f=popen(cmd, "r"); if (!f) { hintbox = new CHintBox(LOCALE_HDD_FORMAT, g_Locale->getText(LOCALE_HDD_FORMAT_FAILED)); hintbox->paint(); sleep(2); delete hintbox; goto _remount; } char buf[256]; setbuf(f, NULL); int n, t, in, pos, stage; pos = 0; stage = 0; while (true) { in = fgetc(f); if (in == EOF) break; buf[pos] = (char)in; pos++; buf[pos] = 0; if (in == '\b' || in == '\n') pos = 0; /* start a new line */ //printf("%s", buf); switch (stage) { case 0: if (strcmp(buf, "Writing inode tables:") == 0) { stage++; progress->showGlobalStatus(20); progress->showStatusMessageUTF(buf); } break; case 1: if (in == '\b' && sscanf(buf, "%d/%d\b", &n, &t) == 2) { int percent = 100 * n / t; progress->showLocalStatus(percent); progress->showGlobalStatus(20 + percent / 5); } if (strstr(buf, "done")) { stage++; pos = 0; } break; case 2: if (strstr(buf, "blocks):") && sscanf(buf, "Creating journal (%d blocks):", &n) == 1) { progress->showLocalStatus(0); progress->showGlobalStatus(60); progress->showStatusMessageUTF(buf); pos = 0; } if (strstr(buf, "done")) { stage++; pos = 0; } break; case 3: if (strcmp(buf, "Writing superblocks and filesystem accounting information:") == 0) { progress->showGlobalStatus(80); progress->showStatusMessageUTF(buf); pos = 0; } break; default: // printf("unknown stage! %d \n\t", stage); break; } } progress->showLocalStatus(100); pclose(f); progress->showGlobalStatus(100); sleep(2); snprintf(cmd, sizeof(cmd), "/sbin/tune2fs -r 0 -c 0 -i 0 %s", src); printf("CHDDFmtExec: executing %s\n", cmd); system(cmd); _remount: progress->hide(); delete progress; switch(g_settings.hdd_fs) { case 0: safe_mkdir(dst); res = mount(src, dst, "ext3", 0, NULL); break; case 1: safe_mkdir(dst); res = mount(src, dst, "reiserfs", 0, NULL); break; default: break; } f = fopen("/proc/sys/kernel/hotplug", "w"); if(f) { fprintf(f, "/sbin/hotplug\n"); fclose(f); } if(!res) { snprintf(cmd, sizeof(cmd), "%s/movies", dst); safe_mkdir((char *) cmd); snprintf(cmd, sizeof(cmd), "%s/pictures", dst); safe_mkdir((char *) cmd); snprintf(cmd, sizeof(cmd), "%s/epg", dst); safe_mkdir((char *) cmd); snprintf(cmd, sizeof(cmd), "%s/music", dst); safe_mkdir((char *) cmd); sync(); #if HAVE_TRIPLEDRAGON /* on the tripledragon, we mount via fstab, so we need to add an fstab entry for dst */ FILE *g; char *line = NULL; unlink("/etc/fstab.new"); g = fopen("/etc/fstab.new", "w"); f = fopen("/etc/fstab", "r"); if (!g) perror("open /etc/fstab.new"); else { if (f) { int ret; while (true) { size_t dummy; ret = getline(&line, &dummy, f); if (ret < 0) break; /* remove lines that start with the same disk we formatted src is "/dev/xda1", we only compare "/dev/xda" */ if (strncmp(line, src, strlen(src)-1) != 0) fprintf(g, "%s", line); } free(line); fclose(f); } /* now add our new entry */ fprintf(g, "%s %s auto defaults 0 0\n", src, dst); fclose(g); rename("/etc/fstab", "/etc/fstab.old"); rename("/etc/fstab.new", "/etc/fstab"); } #endif } _return: if(!srun) system("smbd"); return menu_return::RETURN_REPAINT; }