void KeymapWindow::_FillSystemMaps() { BListItem *item; while ((item = fSystemListView->RemoveItem(static_cast<int32>(0)))) delete item; // TODO: common keymaps! BPath path; if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) != B_OK) return; path.Append("Keymaps"); BDirectory directory; entry_ref ref; if (directory.SetTo(path.Path()) == B_OK) { while (directory.GetNextRef(&ref) == B_OK) { fSystemListView->AddItem(new KeymapListItem(ref)); } } fSystemListView->SortItems(&compare_key_list_items); }
int32_t PDirectoryGetEntries(void *pobject, void *in, void *out, void *extraData) { if (!pobject || !in || !out) return B_ERROR; PDirectory *parent = static_cast<PDirectory*>(pobject); if (!parent) return B_BAD_TYPE; BDirectory *backend = (BDirectory*)parent->GetBackend(); PArgs *outArgs = static_cast<PArgs*>(out); outArgs->MakeEmpty(); PArgs nameList; backend->Rewind(); entry_ref ref; while (backend->GetNextRef(&ref) == B_OK) { if (ref.name) outArgs->AddString("name", ref.name); } return B_OK; }
void AddOnManager::RegisterAddOns() { // Check if add-ons are already registered. if (!fReaderList.IsEmpty() || !fWriterList.IsEmpty() || !fDecoderList.IsEmpty() || !fEncoderList.IsEmpty()) { return; } char** directories = NULL; size_t directoryCount = 0; if (find_paths_etc(get_architecture(), B_FIND_PATH_ADD_ONS_DIRECTORY, "media/plugins", B_FIND_PATH_EXISTING_ONLY, &directories, &directoryCount) != B_OK) { return; } MemoryDeleter directoriesDeleter(directories); BPath path; for (uint i = 0; i < directoryCount; i++) { BDirectory directory; if (directory.SetTo(directories[i]) == B_OK) { entry_ref ref; while(directory.GetNextRef(&ref) == B_OK) _RegisterAddOn(ref); } } }
void KeymapWindow::_FillUserMaps() { BListItem* item; while ((item = fUserListView->RemoveItem(static_cast<int32>(0)))) delete item; entry_ref ref; _GetCurrentKeymap(ref); fUserListView->AddItem(new KeymapListItem(ref, TR("(Current)"))); fCurrentMapName = _GetActiveKeymapName(); BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return; path.Append("Keymap"); BDirectory directory; if (directory.SetTo(path.Path()) == B_OK) { while (directory.GetNextRef(&ref) == B_OK) { fUserListView->AddItem(new KeymapListItem(ref)); } } }
void KeymapWindow::_AddKeyboardLayouts(BMenu* menu) { directory_which dataDirectories[] = { B_USER_DATA_DIRECTORY, B_COMMON_DATA_DIRECTORY, B_BEOS_DATA_DIRECTORY }; for (uint32 i = 0; i < sizeof(dataDirectories) / sizeof(dataDirectories[0]); i++) { BPath path; if (find_directory(dataDirectories[i], &path) != B_OK) continue; path.Append("KeyboardLayouts"); BDirectory directory; if (directory.SetTo(path.Path()) == B_OK) { entry_ref ref; while (directory.GetNextRef(&ref) == B_OK) { if (menu->FindItem(ref.name) != NULL) continue; BMessage* message = new BMessage(kChangeKeyboardLayout); message->AddRef("ref", &ref); menu->AddItem(new BMenuItem(ref.name, message)); } } } }
/*! Adds a menu populated with the keyboard layouts found in the passed in directory to the passed in menu. Each subdirectory in the passed in directory is added as a submenu recursively. */ void KeymapWindow::_AddKeyboardLayoutMenu(BMenu* menu, BDirectory directory) { entry_ref ref; while (directory.GetNextRef(&ref) == B_OK) { if (menu->FindItem(ref.name) != NULL) continue; BDirectory subdirectory; subdirectory.SetTo(&ref); if (subdirectory.InitCheck() == B_OK) { BMenu* submenu = new BMenu(B_TRANSLATE_NOCOLLECT(ref.name)); _AddKeyboardLayoutMenu(submenu, subdirectory); menu->AddItem(submenu); } else { BMessage* message = new BMessage(kChangeKeyboardLayout); message->AddRef("ref", &ref); menu->AddItem(new BMenuItem(B_TRANSLATE_NOCOLLECT(ref.name), message)); } } }
// Function taken from Haiku ShowImage, // function originally written by Michael Pfeiffer bool SlideShowSaver::FindNextImage(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind) { // ASSERT(next || !rewind); BEntry curImage(in_current); entry_ref entry, *ref; BDirectory parent; BList entries; bool found = false; int32 cur; if (curImage.GetParent(&parent) != B_OK) return false; while (parent.GetNextRef(&entry) == B_OK) { if (entry != *in_current) { entries.AddItem(new entry_ref(entry)); } else { // insert current ref, so we can find it easily after sorting entries.AddItem(in_current); } } entries.SortItems(CompareEntries); cur = entries.IndexOf(in_current); // ASSERT(cur >= 0); // remove it so FreeEntries() does not delete it entries.RemoveItem(in_current); if (next) { // find the next image in the list if (rewind) cur = 0; // start with first for (; (ref = (entry_ref*)entries.ItemAt(cur)) != NULL; cur ++) { if (IsImage(ref)) { found = true; *out_image = (const entry_ref)*ref; break; } } } else { // find the previous image in the list cur --; for (; cur >= 0; cur --) { ref = (entry_ref*)entries.ItemAt(cur); if (IsImage(ref)) { found = true; *out_image = (const entry_ref)*ref; break; } } } FreeEntries(&entries); return found; }
status_t DecorInfoUtility::_ScanDecorators(BDirectory decoratorDirectory) { BAutolock _(fLock); // First, run through our list and DecorInfos CheckForChanges() if (fHasScanned) { for (int i = fList.CountItems() - 1; i > 0; --i) { DecorInfo* decorInfo = fList.ItemAt(i); bool deleted = false; decorInfo->CheckForChanges(deleted); if (deleted) { fList.RemoveItem(decorInfo); delete decorInfo; } } } entry_ref ref; // Now, look at file system, skip the entries for which we already have // a DecorInfo in the list. while (decoratorDirectory.GetNextRef(&ref) == B_OK) { BPath path(&decoratorDirectory); status_t result = path.Append(ref.name); if (result != B_OK) { fprintf(stderr, "DecorInfoUtility::_ScanDecorators()\tFailed to" "append decorator file to path, skipping: %s.\n", strerror(result)); continue; } if (_FindDecor(path.Path()) != NULL) continue; DecorInfo* decorInfo = new(std::nothrow) DecorInfo(ref); if (decorInfo == NULL || decorInfo->InitCheck() != B_OK) { fprintf(stderr, "DecorInfoUtility::_ScanDecorators()\tInitCheck() " "failure on decorator, skipping.\n"); delete decorInfo; continue; } fList.AddItem(decorInfo); } return B_OK; }
void VirtualKeyboardWindow::_LoadMaps() { BPath path; if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) != B_OK) return; path.Append("Keymaps"); BDirectory directory; entry_ref ref; if (directory.SetTo(path.Path()) == B_OK) { while (directory.GetNextRef(&ref) == B_OK) { fMapListView->AddItem(new KeymapListItem(ref)); } } fMapListView->SortItems(&compare_key_list_items); }
void BootPromptWindow::_PopulateKeymaps() { // Disable sending the selection message while we change the selection. fKeymapsListView->SetSelectionMessage(NULL); // Clean the list view first while (BListItem* item = fKeymapsListView->RemoveItem( fKeymapsListView->CountItems() - 1)) { delete item; } // Get the name of the current keymap, so we can mark the correct entry // in the list view. BString currentKeymapName; entry_ref ref; if (_GetCurrentKeymapRef(ref) == B_OK) { BNode node(&ref); node.ReadAttrString("keymap:name", ¤tKeymapName); } // TODO: common keymaps! BPath path; if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) != B_OK || path.Append("Keymaps") != B_OK) { return; } // Populate the list BDirectory directory; if (directory.SetTo(path.Path()) == B_OK) { while (directory.GetNextRef(&ref) == B_OK) { fKeymapsListView->AddItem(new KeymapListItem(ref)); if (currentKeymapName == ref.name) fKeymapsListView->Select(fKeymapsListView->CountItems() - 1); } } fKeymapsListView->ScrollToSelection(); // Re-enable sending the selection message. fKeymapsListView->SetSelectionMessage( new BMessage(MSG_KEYMAP_SELECTED)); }
void BootPromptWindow::_PopulateKeymaps() { // Get the name of the current keymap, so we can mark the correct entry // in the list view. BString currentName; entry_ref currentRef; if (_GetCurrentKeymapRef(currentRef) == B_OK) { BNode node(¤tRef); node.ReadAttrString("keymap:name", ¤tName); } // TODO: common keymaps! BPath path; if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) != B_OK || path.Append("Keymaps") != B_OK) { return; } // US-International is the default keymap, if we could not found a // matching one BString usInternational("US-International"); // Populate the menu BDirectory directory; if (directory.SetTo(path.Path()) == B_OK) { entry_ref ref; BList itemsList; while (directory.GetNextRef(&ref) == B_OK) { BMessage* message = new BMessage(MSG_KEYMAP_SELECTED); message->AddRef("ref", &ref); BMenuItem* item = new BMenuItem(ref.name, message); itemsList.AddItem(item); if (currentName == ref.name) item->SetMarked(true); if (usInternational == ref.name) fDefaultKeymapItem = item; } itemsList.SortItems(compare_void_menu_items); fKeymapsMenuField->Menu()->AddList(&itemsList, 0); } }
status_t ThemeManager::LoadThemes() { FENTRY; int dirwhich; BPath path; BDirectory dir; entry_ref ref; status_t err; for (dirwhich = 0; dirwhich < 2; dirwhich++) { if (!dirwhich) /* find system settings dir */ err = find_directory(B_BEOS_ETC_DIRECTORY, &path); else /* find user settings dir */ err = find_directory(B_USER_SETTINGS_DIRECTORY, &path); if (err) return err; err = dir.SetTo(path.Path()); if (err) return err; BEntry ent; if (dir.FindEntry(Z_THEMES_FOLDER_NAME, &ent) < B_OK) { dir.CreateDirectory(Z_THEMES_FOLDER_NAME, NULL); } path.Append(Z_THEMES_FOLDER_NAME); err = dir.SetTo(path.Path()); if (err) return err; err = dir.Rewind(); if (err) return err; while ((err = dir.GetNextRef(&ref)) == B_OK) { BPath themepath(&ref); BDirectory tdir(themepath.Path()); err = tdir.InitCheck(); if (err) /* not a dir */ continue; err = LoadTheme(themepath.Path()); } } return B_OK; }
PowerButtonMonitor::PowerButtonMonitor() : fFDs() { BDirectory dir; if (dir.SetTo(kBasePath) != B_OK) return; entry_ref ref; while (dir.GetNextRef(&ref) == B_OK) { if (strncmp(ref.name, "power", 5) == 0) { BString path; path.SetToFormat("%s/%s", kBasePath, ref.name); int fd = open(path.String(), O_RDONLY); if (fd > 0) fFDs.insert(fd); } } }
void VirtualKeyboardWindow::_LoadLayoutMenu(BMenu* menu, BDirectory directory) { entry_ref ref; while (directory.GetNextRef(&ref) == B_OK) { if (menu->FindItem(ref.name) != NULL) continue; BDirectory subdirectory; subdirectory.SetTo(&ref); if (subdirectory.InitCheck() == B_OK) { BMenu* submenu = new BMenu(ref.name); _LoadLayoutMenu(submenu, subdirectory); menu->AddItem(submenu); } else { //BMessage* message = new BMessage(kChangeKeyboardLayout); //message->AddRed("ref",&ref); menu->AddItem(new BMenuItem(ref.name, NULL)); } } }
BPopUpMenu* DeskbarView::_BuildMenu() { BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false); menu->SetFont(be_plain_font); menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE ( "Create new message", "N) 新規メッセージ作成")B_UTF8_ELLIPSIS, new BMessage(MD_OPEN_NEW))); menu->AddSeparatorItem(); BMessenger tracker(kTrackerSignature); BNavMenu* navMenu; BMenuItem* item; BMessage* msg; entry_ref ref; BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Mail/Menu Links"); BDirectory directory; if (_CreateMenuLinks(directory, path)) { int32 count = 0; while (directory.GetNextRef(&ref) == B_OK) { count++; path.SetTo(&ref); // the true here dereferences the symlinks all the way :) BEntry entry(&ref, true); // do we want to use the NavMenu, or just an ordinary BMenuItem? // we are using the NavMenu only for directories and queries bool useNavMenu = false; if (entry.InitCheck() == B_OK) { if (entry.IsDirectory()) useNavMenu = true; else if (entry.IsFile()) { // Files should use the BMenuItem unless they are queries char mimeString[B_MIME_TYPE_LENGTH]; BNode node(&entry); BNodeInfo info(&node); if (info.GetType(mimeString) == B_OK && strcmp(mimeString, "application/x-vnd.Be-query") == 0) useNavMenu = true; } // clobber the existing ref only if the symlink derefernces // completely, otherwise we'll stick with what we have entry.GetRef(&ref); } msg = new BMessage(B_REFS_RECEIVED); msg->AddRef("refs", &ref); if (useNavMenu) { item = new BMenuItem(navMenu = new BNavMenu(path.Leaf(), B_REFS_RECEIVED, tracker), msg); navMenu->SetNavDir(&ref); } else item = new BMenuItem(path.Leaf(), msg); menu->AddItem(item); if(entry.InitCheck() != B_OK) item->SetEnabled(false); } if (count > 0) menu->AddSeparatorItem(); } // Hack for R5's buggy Query Notification #ifdef HAIKU_TARGET_PLATFORM_BEOS menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE("Refresh New Mail Count", "未読メールカウントを更新"), new BMessage(MD_REFRESH_QUERY))); #endif // The New E-mail query if (fNewMessages > 0) { BString string; MDR_DIALECT_CHOICE( string << fNewMessages << " new message" << (fNewMessages != 1 ? "s" : B_EMPTY_STRING), string << fNewMessages << " 通の未読メッセージ"); _GetNewQueryRef(ref); item = new BMenuItem(navMenu = new BNavMenu(string.String(), B_REFS_RECEIVED, BMessenger(kTrackerSignature)), msg = new BMessage(B_REFS_RECEIVED)); msg->AddRef("refs", &ref); navMenu->SetNavDir(&ref); menu->AddItem(item); } else { menu->AddItem(item = new BMenuItem( MDR_DIALECT_CHOICE ("No new messages","未読メッセージなし"), NULL)); item->SetEnabled(false); } BMailAccounts accounts; if (modifiers() & B_SHIFT_KEY) { BMenu *accountMenu = new BMenu( MDR_DIALECT_CHOICE ("Check for mails only","R) メール受信のみ")); BFont font; menu->GetFont(&font); accountMenu->SetFont(&font); for (int32 i = 0; i < accounts.CountAccounts(); i++) { BMailAccountSettings* account = accounts.AccountAt(i); BMessage* message = new BMessage(MD_CHECK_FOR_MAILS); message->AddInt32("account", account->AccountID()); accountMenu->AddItem(new BMenuItem(account->Name(), message)); } if (accounts.CountAccounts() == 0) { item = new BMenuItem("<no accounts>", NULL); item->SetEnabled(false); accountMenu->AddItem(item); } accountMenu->SetTargetForItems(this); menu->AddItem(new BMenuItem(accountMenu, new BMessage(MD_CHECK_FOR_MAILS))); // Not used: // menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE ( // "Check For Mails Only","メール受信のみ"), new BMessage(MD_CHECK_FOR_MAILS))); menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Send pending mails", "M) 保留メールを送信"), new BMessage(MD_SEND_MAILS))); } else { menu->AddItem(item = new BMenuItem( MDR_DIALECT_CHOICE ("Check for mail now", "C) メールチェック"), new BMessage(MD_CHECK_SEND_NOW))); if (accounts.CountAccounts() == 0) item->SetEnabled(false); } menu->AddSeparatorItem(); menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Preferences", "P) メール環境設定") B_UTF8_ELLIPSIS, new BMessage(MD_OPEN_PREFS))); if (modifiers() & B_SHIFT_KEY) { menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Shutdown mail services", "Q) 終了"), new BMessage(B_QUIT_REQUESTED))); } // Reset Item Targets (only those which aren't already set) for (int32 i = menu->CountItems(); i-- > 0;) { item = menu->ItemAt(i); if (item && (msg = item->Message()) != NULL) { if (msg->what == B_REFS_RECEIVED) item->SetTarget(tracker); else item->SetTarget(this); } } return menu; }
void ProjectWindow::AddFolder(entry_ref folderref) { BDirectory dir; if (dir.SetTo(&folderref) != B_OK) return; if (strcmp(folderref.name,"CVS") == 0 || strcmp(folderref.name,".svn") == 0 || strcmp(folderref.name,".git") == 0 || strcmp(folderref.name,".hg") == 0) return; dir.Rewind(); entry_ref ref; while (dir.GetNextRef(&ref) == B_OK) { if (BEntry(&ref).IsDirectory()) AddFolder(ref); else { // Here is where we actually add the file to the project. The name of the folder // containing the file will be the name of the file's group. If the group doesn't // exist, it will be created at the end of the list, but if it does, we will fake // a drop onto the group item to reuse the code path by finding the group and getting // its position in the list. DPath filepath(ref); if (filepath.GetExtension() && !( strcmp(filepath.GetExtension(),"cpp") == 0 || strcmp(filepath.GetExtension(),"c") == 0 || strcmp(filepath.GetExtension(),"cc") == 0 || strcmp(filepath.GetExtension(),"cxx") == 0 || strcmp(filepath.GetExtension(),"rdef") == 0 || strcmp(filepath.GetExtension(),"rsrc") == 0) ) continue; // Don't bother adding build files from other systems if (strcmp(filepath.GetFileName(), "Jamfile") == 0 || strcmp(filepath.GetFileName(), "Makefile") == 0) continue; DPath parent(filepath.GetFolder()); SourceGroup *group = NULL; SourceGroupItem *groupItem = NULL; fProject->Lock(); group = fProject->FindGroup(parent.GetFileName()); Lock(); if (group) groupItem = fProjectList->ItemForGroup(group); else { group = fProject->AddGroup(parent.GetFileName()); groupItem = new SourceGroupItem(group); fProjectList->AddItem(groupItem); UpdateIfNeeded(); } if (groupItem) { int32 index = fProjectList->IndexOf(groupItem); BPoint pt = fProjectList->ItemFrame(index).LeftTop(); pt.x += 5; pt.y += 5; AddFile(ref,&pt); } Unlock(); fProject->Unlock(); } } }
status_t ThemeManager::LoadAddons() { FENTRY; ThemesAddon *ta; BPath path; BDirectory dir; entry_ref ref; #ifndef SINGLE_BINARY uint32 addonFlags; int dirwhich; int32 i; status_t err; image_id img; ThemesAddon *(*instantiate_func)(); #endif #ifndef SINGLE_BINARY for (dirwhich = 0; dirwhich < 2; dirwhich++) { if (!dirwhich) /* find system settings dir */ err = find_directory(B_BEOS_ADDONS_DIRECTORY, &path); else /* find user settings dir */ err = find_directory(B_USER_ADDONS_DIRECTORY, &path); if (err) return err; path.Append(Z_THEMES_ADDON_FOLDER); err = dir.SetTo(path.Path()); if (err) continue; err = dir.Rewind(); if (err) continue; while ((err = dir.GetNextRef(&ref)) == B_OK) { bool screwed = false; BPath imgpath(&ref); BString p(Z_THEMES_ADDON_FOLDER); p << "/" << ref.name; PRINT(("ThemeManager: trying to load_add_on(%s)\n", p.String())); img = load_add_on(imgpath.Path()); if (img < B_OK) fprintf(stderr, "ThemeManager: load_add_on 0x%08lx\n", img); if (img < B_OK) continue; err = get_image_symbol(img, "instantiate_themes_addon", B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func); if (err) fprintf(stderr, "ThemeManager: get_image_symbol 0x%08lx\n", err); if (err) continue; ta = instantiate_func(); if (!ta) fprintf(stderr, "ThemeManager: instantiate_themes_addon returned NULL\n"); if (!ta) continue; ta->SetImageId(img); /* check for existing names */ for (i = 0; i < fAddonList.CountItems(); i++) { ThemesAddon *a = AddonAt(i); if (!a) fprintf(stderr, "ThemeManager: screwed! addon@%ld null\n", i); if (a->MessageName() && ta->MessageName() && !strcmp(a->MessageName(), ta->MessageName())) { fprintf(stderr, "ThemeManager: screwed! addon@%ld has same msgname\n", i); screwed = true; break; } if (a->Name() && ta->Name() && !strcmp(a->Name(), ta->Name())) { fprintf(stderr, "ThemeManager: screwed! addon@%ld has same name\n", i); screwed = true; break; } } if (screwed) continue; /* add it to the list */ fAddonList.AddItem((void *)ta); PRINT(("ThemeManager: Added addon %ld '%s', msgname '%s'\n", ta->ImageId(), ta->Name(), ta->MessageName())); } //if (err) return err; } #else #define ADDA(a) \ if (ta) { \ fAddonList.AddItem((void *)ta); \ PRINT(("ThemeManager: Added addon %ld '%s', msgname '%s'\n", ta->ImageId(), ta->Name(), ta->MessageName())); \ } ta = instantiate_themes_addon_backgrounds(); ADDA(ta); ta = instantiate_themes_addon_beide(); ADDA(ta); ta = instantiate_themes_addon_deskbar(); ADDA(ta); #ifndef ZETA_ADDONS ta = instantiate_themes_addon_eddie(); ADDA(ta); #endif ta = instantiate_themes_addon_pe(); ADDA(ta); ta = instantiate_themes_addon_screensaver(); ADDA(ta); #ifndef ZETA_ADDONS ta = instantiate_themes_addon_soundplay(); ADDA(ta); #endif ta = instantiate_themes_addon_sounds(); ADDA(ta); ta = instantiate_themes_addon_terminal(); ADDA(ta); #if defined(__ANTARES__) || defined(B_BEOS_VERSION_DANO) ta = instantiate_themes_addon_ui_settings(); ADDA(ta); #endif #ifndef ZETA_ADDONS ta = instantiate_themes_addon_winamp_skin(); ADDA(ta); #endif ta = instantiate_themes_addon_window_decor(); ADDA(ta); #endif //if (err) return err; fAddonCount = fAddonList.CountItems(); PRINT(("ThemeManager: %ld addons loaded\n", fAddonCount)); return B_OK; }
void WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu) { CALLED(); BPath targetDirectory; BPath srcDirectory; BPath trashPath; BPath testPath; BDirectory targetDir; BDiskDevice device; BPartition* partition; BVolume targetVolume; status_t err = B_OK; int32 entries = 0; entry_ref testRef; const char* mountError = B_TRANSLATE("The disk can't be mounted. Please " "choose a different disk."); BMessenger messenger(fWindow); ProgressReporter reporter(messenger, new BMessage(MSG_STATUS_MESSAGE)); CopyEngine engine(&reporter); BList unzipEngines; PartitionMenuItem* targetItem = (PartitionMenuItem*)targetMenu->FindMarked(); PartitionMenuItem* srcItem = (PartitionMenuItem*)srcMenu->FindMarked(); if (!srcItem || !targetItem) { ERR("bad menu items\n"); goto error; } // check if target is initialized // ask if init or mount as is if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) { if (!partition->IsMounted()) { if ((err = partition->Mount()) < B_OK) { _SetStatusMessage(mountError); ERR("BPartition::Mount"); goto error; } } if ((err = partition->GetVolume(&targetVolume)) != B_OK) { ERR("BPartition::GetVolume"); goto error; } if ((err = partition->GetMountPoint(&targetDirectory)) != B_OK) { ERR("BPartition::GetMountPoint"); goto error; } } else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) { if (!device.IsMounted()) { if ((err = device.Mount()) < B_OK) { _SetStatusMessage(mountError); ERR("BDiskDevice::Mount"); goto error; } } if ((err = device.GetVolume(&targetVolume)) != B_OK) { ERR("BDiskDevice::GetVolume"); goto error; } if ((err = device.GetMountPoint(&targetDirectory)) != B_OK) { ERR("BDiskDevice::GetMountPoint"); goto error; } } else goto error; // shouldn't happen // check if target has enough space if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired) && ((new BAlert("", B_TRANSLATE("The destination disk may not have " "enough space. Try choosing a different disk or choose to not " "install optional items."), B_TRANSLATE("Try installing anyway"), B_TRANSLATE("Cancel"), 0, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { goto error; } if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) { if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) { ERR("BPartition::GetMountPoint"); goto error; } } else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) { if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) { ERR("BDiskDevice::GetMountPoint"); goto error; } } else goto error; // shouldn't happen // check not installing on itself if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) { _SetStatusMessage(B_TRANSLATE("You can't install the contents of a " "disk onto itself. Please choose a different disk.")); goto error; } // check not installing on boot volume if ((strncmp(BOOT_PATH, targetDirectory.Path(), strlen(BOOT_PATH)) == 0) && ((new BAlert("", B_TRANSLATE("Are you sure you want to install " "onto the current boot disk? The Installer will have to reboot " "your machine if you proceed."), B_TRANSLATE("OK"), B_TRANSLATE("Cancel"), 0, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { _SetStatusMessage("Installation stopped."); goto error; } // check if target volume's trash dir has anything in it // (target volume w/ only an empty trash dir is considered // an empty volume) if (find_directory(B_TRASH_DIRECTORY, &trashPath, false, &targetVolume) == B_OK && targetDir.SetTo(trashPath.Path()) == B_OK) { while (targetDir.GetNextRef(&testRef) == B_OK) { // Something in the Trash entries++; break; } } targetDir.SetTo(targetDirectory.Path()); // check if target volume otherwise has any entries while (entries == 0 && targetDir.GetNextRef(&testRef) == B_OK) { if (testPath.SetTo(&testRef) == B_OK && testPath != trashPath) entries++; } if (entries != 0 && ((new BAlert("", B_TRANSLATE("The target volume is not empty. Are " "you sure you want to install anyway?\n\nNote: The 'system' folder " "will be a clean copy from the source volume, all other folders " "will be merged, whereas files and links that exist on both the " "source and target volume will be overwritten with the source " "volume version."), B_TRANSLATE("Install anyway"), B_TRANSLATE("Cancel"), 0, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { // TODO: Would be cool to offer the option here to clean additional // folders at the user's choice (like /boot/common and /boot/develop). err = B_CANCELED; goto error; } // Begin actual installation _LaunchInitScript(targetDirectory); // Create the default indices which should always be present on a proper // boot volume. We don't care if the source volume does not have them. // After all, the user might be re-installing to another drive and may // want problems fixed along the way... err = _CreateDefaultIndices(targetDirectory); if (err != B_OK) goto error; // Mirror all the indices which are present on the source volume onto // the target volume. err = _MirrorIndices(srcDirectory, targetDirectory); if (err != B_OK) goto error; // Let the engine collect information for the progress bar later on engine.ResetTargets(srcDirectory.Path()); err = engine.CollectTargets(srcDirectory.Path(), fCancelSemaphore); if (err != B_OK) goto error; // Collect selected packages also if (fPackages) { BPath pkgRootDir(srcDirectory.Path(), PACKAGES_DIRECTORY); int32 count = fPackages->CountItems(); for (int32 i = 0; i < count; i++) { Package *p = static_cast<Package*>(fPackages->ItemAt(i)); BPath packageDir(pkgRootDir.Path(), p->Folder()); err = engine.CollectTargets(packageDir.Path(), fCancelSemaphore); if (err != B_OK) goto error; } } // collect information about all zip packages err = _ProcessZipPackages(srcDirectory.Path(), targetDirectory.Path(), &reporter, unzipEngines); if (err != B_OK) goto error; reporter.StartTimer(); // copy source volume err = engine.CopyFolder(srcDirectory.Path(), targetDirectory.Path(), fCancelSemaphore); if (err != B_OK) goto error; // copy selected packages if (fPackages) { BPath pkgRootDir(srcDirectory.Path(), PACKAGES_DIRECTORY); int32 count = fPackages->CountItems(); for (int32 i = 0; i < count; i++) { Package *p = static_cast<Package*>(fPackages->ItemAt(i)); BPath packageDir(pkgRootDir.Path(), p->Folder()); err = engine.CopyFolder(packageDir.Path(), targetDirectory.Path(), fCancelSemaphore); if (err != B_OK) goto error; } } // Extract all zip packages. If an error occured, delete the rest of // the engines, but stop extracting. for (int32 i = 0; i < unzipEngines.CountItems(); i++) { UnzipEngine* engine = reinterpret_cast<UnzipEngine*>( unzipEngines.ItemAtFast(i)); if (err == B_OK) err = engine->UnzipPackage(); delete engine; } if (err != B_OK) goto error; _LaunchFinishScript(targetDirectory); BMessenger(fWindow).SendMessage(MSG_INSTALL_FINISHED); return; error: BMessage statusMessage(MSG_RESET); if (err == B_CANCELED) _SetStatusMessage(B_TRANSLATE("Installation canceled.")); else statusMessage.AddInt32("error", err); ERR("_PerformInstall failed"); BMessenger(fWindow).SendMessage(&statusMessage); }
// _LoadAddOns status_t DiskSystemAddOnManager::_LoadAddOns(StringSet& alreadyLoaded, directory_which addOnDir) { // get the add-on directory path BPath path; status_t error = find_directory(addOnDir, &path, false); if (error != B_OK) return error; TRACE("DiskSystemAddOnManager::_LoadAddOns(): %s\n", path.Path()); error = path.Append("disk_systems"); if (error != B_OK) return error; if (!BEntry(path.Path()).Exists()) return B_OK; // open the directory and iterate through its entries BDirectory directory; error = directory.SetTo(path.Path()); if (error != B_OK) return error; entry_ref ref; while (directory.GetNextRef(&ref) == B_OK) { // skip, if already loaded if (alreadyLoaded.find(ref.name) != alreadyLoaded.end()) { TRACE(" skipping \"%s\" -- already loaded\n", ref.name); continue; } // get the entry path BPath entryPath; error = entryPath.SetTo(&ref); if (error != B_OK) { if (error == B_NO_MEMORY) return error; TRACE(" skipping \"%s\" -- failed to get path\n", ref.name); continue; } // load the add-on image_id image = load_add_on(entryPath.Path()); if (image < 0) { TRACE(" skipping \"%s\" -- failed to load add-on\n", ref.name); continue; } AddOnImage* addOnImage = new(nothrow) AddOnImage(image); if (!addOnImage) { unload_add_on(image); return B_NO_MEMORY; } ObjectDeleter<AddOnImage> addOnImageDeleter(addOnImage); // get the add-on objects status_t (*getAddOns)(BList*); error = get_image_symbol(image, "get_disk_system_add_ons", B_SYMBOL_TYPE_TEXT, (void**)&getAddOns); if (error != B_OK) { TRACE(" skipping \"%s\" -- function symbol not found\n", ref.name); continue; } BList addOns; error = getAddOns(&addOns); if (error != B_OK || addOns.IsEmpty()) { TRACE(" skipping \"%s\" -- getting add-ons failed\n", ref.name); continue; } // create and add AddOn objects int32 count = addOns.CountItems(); for (int32 i = 0; i < count; i++) { BDiskSystemAddOn* diskSystemAddOn = (BDiskSystemAddOn*)addOns.ItemAt(i); AddOn* addOn = new(nothrow) AddOn(addOnImage, diskSystemAddOn); if (!addOn) return B_NO_MEMORY; if (fAddOns.AddItem(addOn)) { addOnImage->refCount++; addOnImageDeleter.Detach(); } else { delete addOn; return B_NO_MEMORY; } } TRACE(" got %ld BDiskSystemAddOn(s) from add-on \"%s\"\n", count, ref.name); // add the add-on name to the set of already loaded add-ons try { alreadyLoaded.insert(ref.name); } catch (std::bad_alloc& exception) { return B_NO_MEMORY; } } return B_OK; }