void EnsureTemplates(void) { // Because creating a new project depends on the existence of the Templates folder, // make sure that we have some (very) basic templates to work with if the folder // has been deleted. DPath templatePath = gAppPath.GetFolder(); templatePath << "Templates"; bool missing = false; BDirectory tempDir; if (!BEntry(templatePath.GetFullPath()).Exists()) { BDirectory appDir(gAppPath.GetFolder()); appDir.CreateDirectory("Templates", &tempDir); missing = true; } else { tempDir.SetTo(templatePath.GetFullPath()); if (tempDir.CountEntries() == 0) missing = true; } if (missing) { BDirectory dir; tempDir.CreateDirectory("Empty Application", &dir); tempDir.CreateDirectory("Kernel Driver", &dir); tempDir.CreateDirectory("Shared Library or Addon", &dir); tempDir.CreateDirectory("Static Library", &dir); DPath filePath; TextFile file; filePath = templatePath; filePath << "Empty Application/TEMPLATEINFO"; file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE); file.WriteString("TYPE=Application\nLIB=B_BEOS_LIB_DIRECTORY/libsupc++.so\n"); filePath = templatePath; filePath << "Kernel Driver/TEMPLATEINFO"; file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE); file.WriteString("TYPE=Driver\n"); filePath = templatePath; filePath << "Shared Library or Addon/TEMPLATEINFO"; file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE); file.WriteString("TYPE=Shared\n"); filePath = templatePath; filePath << "Static Library/TEMPLATEINFO"; file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE); file.WriteString("TYPE=Static\n"); file.Unset(); } }
status_t ZKWindow::MakeSettingsFolder (void) { PRINT(("ZKWindow::MakeSettingsFolder()\n")); status_t status; BPath path; if ((status = find_directory(B_USER_SETTINGS_DIRECTORY, & path)) != B_OK) return status; BEntry entry (path.Path()); // settings if (entry.Exists() == false || entry.IsDirectory() == false) return B_ERROR; BDirectory mother (path.Path()); BDirectory baby; // Kirilla path.SetTo(path.Path(), "Kirilla"); entry.SetTo(path.Path()); if (! entry.Exists()) { status = mother.CreateDirectory("Kirilla", & baby); if (status != B_OK && status != B_FILE_EXISTS) return status; } else if (! entry.IsDirectory()) return B_FILE_EXISTS; if ((status = mother.SetTo(path.Path())) != B_OK) return status; // ZooKeeper path.SetTo(path.Path(), "ZooKeeper"); entry.SetTo(path.Path()); if (! entry.Exists()) { status = mother.CreateDirectory("ZooKeeper", & baby); if (status != B_OK && status != B_FILE_EXISTS) return status; } else if (! entry.IsDirectory()) return B_FILE_EXISTS; if ((status = mother.SetTo(path.Path())) != B_OK) return status; entry.SetTo(path.Path()); if (entry.Exists() && entry.IsDirectory()) return B_OK; else return B_ERROR; }
BootManagerController::BootManagerController() : fBootDrive(NULL), fBootMenu(NULL) { // set defaults fSettings.AddBool("install", true); fSettings.AddInt32("defaultPartition", 0); fSettings.AddInt32("timeout", -1); BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { path.Append("bootman/MBR"); fSettings.AddString("file", path.Path()); // create directory BPath parent; if (path.GetParent(&parent) == B_OK) { BDirectory directory; directory.CreateDirectory(parent.Path(), NULL); } } else { fSettings.AddString("file", ""); } // That's the only boot menu we support at the moment. fBootMenus.AddItem(new LegacyBootMenu()); }
status_t MSNP::Init(CayaProtocolMessengerInterface* msgr) { fServerMsgr = msgr; fLogged = false; fClientID = 0; fClientID += MSN::MSNC7; fClientID += MSN::MSNC6; fClientID += MSN::MSNC5; fClientID += MSN::MSNC4; fClientID += MSN::MSNC3; fClientID += MSN::MSNC2; fClientID += MSN::MSNC1; fClientID += MSN::SupportWinks; fClientID += MSN::VoiceClips; fClientID += MSN::InkGifSupport; fClientID += MSN::SIPInvitations; fClientID += MSN::SupportMultiPacketMessaging; fID = 963396; BPath path; status_t ret = find_directory(B_USER_CONFIG_DIRECTORY, &path); if (ret != B_OK) return ret; BDirectory cacheDir = BDirectory(path.Path()); path.Append("settings/Caya/Cache/msn/"); cacheDir.CreateDirectory(path.Path(), NULL); fCachePath = path; return B_OK; }
void PersonWindow::SaveAs() { char name[B_FILE_NAME_LENGTH]; _GetDefaultFileName(name); if (fPanel == NULL) { BMessenger target(this); fPanel = new BFilePanel(B_SAVE_PANEL, &target); BPath path; find_directory(B_USER_DIRECTORY, &path, true); BDirectory dir; dir.SetTo(path.Path()); BEntry entry; if (dir.FindEntry("people", &entry) == B_OK || (dir.CreateDirectory("people", &dir) == B_OK && dir.GetEntry(&entry) == B_OK)) { fPanel->SetPanelDirectory(&entry); } } if (fPanel->Window()->Lock()) { fPanel->SetSaveText(name); if (fPanel->Window()->IsHidden()) fPanel->Window()->Show(); else fPanel->Window()->Activate(); fPanel->Window()->Unlock(); } }
status_t ThemeManager::SaveTheme(int32 id, bool excl) { FENTRY; status_t err; BString name, fname; BPath path; BDirectory dir; BDirectory tdir; BFile tfile; BMessage names; BString location; BMessage *theme; theme = ThemeAt(id); if (!theme) return EINVAL; err = find_directory(B_USER_SETTINGS_DIRECTORY, &path); if (err) return err; path.Append(Z_THEMES_FOLDER_NAME); err = dir.SetTo(path.Path()); if (err) return err; err = ThemeName(id, name); if (err) return err; fname = name; NormalizeThemeFolderName(fname); err = ThemeLocation(id, location); if (!err) { if (location.FindFirst("/boot/beos") >= 0) { PRINT(("trying to save theme '%s' to system dir!\n", name.String())); return B_PERMISSION_DENIED; } } path.Append(fname.String()); err = theme->ReplaceString(Z_THEME_LOCATION, path.Path()); if (err) err = theme->AddString(Z_THEME_LOCATION, path.Path()); if (dir.CreateDirectory(fname.String(), NULL) < B_OK) { if (excl) return B_FILE_EXISTS; } err = tdir.SetTo(&dir, fname.String()); if (err) return err; err = tdir.CreateFile(Z_THEME_FILE_NAME, &tfile); if (err) return err; BMessage tosave(*theme); err = tosave.RemoveName(Z_THEME_LOCATION); err = GetNames(names); err = DumpMessageToStream(&tosave, tfile, 0, &names); if (err) return err; return B_OK; }
status_t GetSettingsDir(BDirectory &dir, BPath &path) { //BPath path; status_t err; // TODO: build list from text files err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); if (err < B_OK) return err; dir.SetTo(path.Path()); if (!dir.Contains("pe")) dir.CreateDirectory("pe", NULL); path.Append("pe"); dir.SetTo(path.Path()); if (!dir.Contains("HeaderTemplates")) dir.CreateDirectory("HeaderTemplates", NULL); path.Append("HeaderTemplates"); dir.SetTo(path.Path()); return B_OK; }
status_t BDaemonClient::CreateTransaction(BPackageInstallationLocation location, BActivationTransaction& _transaction, BDirectory& _transactionDirectory) { // get an info for the location BInstallationLocationInfo info; status_t error = GetInstallationLocationInfo(location, info); if (error != B_OK) return error; // open admin directory entry_ref entryRef; entryRef.device = info.PackagesDirectoryRef().device; entryRef.directory = info.PackagesDirectoryRef().node; error = entryRef.set_name(PACKAGES_DIRECTORY_ADMIN_DIRECTORY); if (error != B_OK) return error; BDirectory adminDirectory; error = adminDirectory.SetTo(&entryRef); if (error != B_OK) return error; // create a transaction directory int uniqueId = 1; BString directoryName; for (;; uniqueId++) { directoryName.SetToFormat("transaction-%d", uniqueId); if (directoryName.IsEmpty()) return B_NO_MEMORY; error = adminDirectory.CreateDirectory(directoryName, &_transactionDirectory); if (error == B_OK) break; if (error != B_FILE_EXISTS) return error; } // init the transaction error = _transaction.SetTo(location, info.ChangeCount(), directoryName); if (error != B_OK) { BEntry entry; _transactionDirectory.GetEntry(&entry); _transactionDirectory.Unset(); if (entry.InitCheck() == B_OK) entry.Remove(); return error; } return B_OK; }
void TBarWindow::MenusBeginning() { BPath path; entry_ref ref; find_directory (B_USER_DESKBAR_DIRECTORY, &path); get_ref_for_path(path.Path(), &ref); BEntry entry(&ref, true); if (entry.InitCheck() == B_OK && entry.IsDirectory()) { // need the entry_ref to the actual item entry.GetRef(&ref); // set the nav directory to the deskbar folder sDeskbarMenu->SetNavDir(&ref); } else if (!entry.Exists()) { // the deskbar folder does not exist // create one now BDirectory dir; if (entry.GetParent(&dir) == B_OK) { BDirectory deskbarDir; dir.CreateDirectory("deskbar", &deskbarDir); if (deskbarDir.GetEntry(&entry) == B_OK && entry.GetRef(&ref) == B_OK) sDeskbarMenu->SetNavDir(&ref); } } else { // this really should never happen TRESPASS(); return; } sDeskbarMenu->NeedsToRebuild(); sDeskbarMenu->ResetTargets(); fBarView->SetEventMask(0); // This works around a BeOS bug - the menu is quit with every // B_MOUSE_DOWN the window receives. // // Is this bug still here? I commented this line out and didn't // notice anything different BWindow::MenusBeginning(); }
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; }
bool DeskbarView::_CreateMenuLinks(BDirectory& directory, BPath& path) { status_t status = directory.SetTo(path.Path()); if (status == B_OK) return true; // Check if the directory has to be created (and do it in this case, // filling it with some standard links). Normally the installer will // create the directory and fill it with links, so normally this doesn't // get used. BEntry entry(path.Path()); if (status != B_ENTRY_NOT_FOUND || entry.GetParent(&directory) < B_OK || directory.CreateDirectory(path.Leaf(), NULL) < B_OK || directory.SetTo(path.Path()) < B_OK) return false; BPath targetPath; find_directory(B_USER_DIRECTORY, &targetPath); targetPath.Append("mail/in"); directory.CreateSymLink("Open Inbox Folder", targetPath.Path(), NULL); targetPath.GetParent(&targetPath); directory.CreateSymLink("Open Mail Folder", targetPath.Path(), NULL); // create the draft query BFile file; if (directory.CreateFile("Open Draft", &file) < B_OK) return true; BString string("MAIL:draft==1"); file.WriteAttrString("_trk/qrystr", &string); string = "E-mail"; file.WriteAttrString("_trk/qryinitmime", &string); BNodeInfo(&file).SetType("application/x-vnd.Be-query"); return true; }
int32_t PDirectoryCreateDirectory(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 *args = static_cast<PArgs*>(in), *outArgs = static_cast<PArgs*>(out); BString path; if (args->FindString("path", &path) != B_OK) return B_ERROR; BDirectory newDir; status_t status = backend->CreateDirectory(path.String(), &newDir); outArgs->MakeEmpty(); if (status == B_OK) { BEntry entry; status = newDir.GetEntry(&entry); if (status == B_OK) { BPath dirPath; status = entry.GetPath(&dirPath); outArgs->AddString("path", dirPath.Path()); } } outArgs->AddInt32("status", status); return B_OK; }
void PersonWindow::SaveAs(int32 format) { if (format == 0) format = B_PERSON_FORMAT; char name[B_FILE_NAME_LENGTH]; _GetDefaultFileName(name); if (fPanel == NULL) { BPath path; BMessenger target(this); BMessage msg(B_SAVE_REQUESTED); msg.AddInt32("format", format); fPanel = new BFilePanel(B_SAVE_PANEL, &target, NULL, 0, true, &msg); find_directory(B_USER_DIRECTORY, &path, true); BDirectory dir; dir.SetTo(path.Path()); BEntry entry; if (dir.FindEntry("people", &entry) == B_OK || (dir.CreateDirectory("people", &dir) == B_OK && dir.GetEntry(&entry) == B_OK)) { fPanel->SetPanelDirectory(&entry); } } if (fPanel->Window()->Lock()) { fPanel->SetSaveText(name); if (fPanel->Window()->IsHidden()) fPanel->Window()->Show(); else fPanel->Window()->Activate(); fPanel->Window()->Unlock(); } }
NotificationWindow::NotificationWindow() : BWindow(BRect(0, 0, -1, -1), B_TRANSLATE_MARK("Notification"), B_BORDERED_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL, B_AVOID_FRONT | B_AVOID_FOCUS | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_NOT_MOVABLE | B_AUTO_UPDATE_SIZE_LIMITS, B_ALL_WORKSPACES), fShouldRun(true) { status_t result = find_directory(B_USER_CACHE_DIRECTORY, &fCachePath); fCachePath.Append("Notifications"); BDirectory cacheDir; result = cacheDir.SetTo(fCachePath.Path()); if (result == B_ENTRY_NOT_FOUND) cacheDir.CreateDirectory(fCachePath.Path(), NULL); SetLayout(new BGroupLayout(B_VERTICAL, 0)); _LoadSettings(true); // Start the message loop Hide(); Show(); }
BFile* MilkySettingsApplication::_OpenSettingsFile(uint32 openMode) { BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("MilkyTracker"); BEntry dirEntry(path.Path()); if (!dirEntry.Exists()) { // MilkyTracker settings dir doesn't exist, create it BDirectory temp; temp.CreateDirectory(path.Path(), NULL); } path.Append("platform_settings"); BFile* file = new BFile(path.Path(), openMode); if (file->InitCheck() != B_OK) { delete file; return NULL; } return file; }
void SNewFolderWindow::CreateFolder() { char newPath[B_PATH_NAME_LENGTH]; BString text(iNameTextControl->Text()); if(text.Compare(".")==0 || text.Compare("..")==0) { BAlert *alert=new BAlert("Error", "The names '.' and '..' refer to" " the current folder and its parent, respectively. Please choose" " another name.", "OK"); alert->Go(); return; } if(text.CountChars()==0) return; strcpy(newPath, iParentFile->PathDesc()); strcat(newPath, "/"); strcat(newPath, iNameTextControl->Text()); BDirectory directory; status_t rc; rc=directory.CreateDirectory(newPath, 0); if(rc!=B_OK) { char errMsg[80]; switch (rc) { case B_BAD_VALUE: strcpy(errMsg, "The folder cannot be created because an " "invalid folder name was given (possibly because of illegal characters)"); break; case B_FILE_EXISTS: strcpy(errMsg, "The folder cannot be created because the name " "given is already in use"); break; case B_NAME_TOO_LONG : strcpy(errMsg, "The folder cannot be created because the name " "given is too long"); break; case B_NOT_ALLOWED: strcpy(errMsg, "The folder cannot be created because the target " "volume is read-only"); break; case B_PERMISSION_DENIED: strcpy(errMsg, "The folder cannot be created because you do not " "have sufficient privileges on the target folder"); break; default : sprintf(errMsg, "The folder cannot be created because an unexpected error " "occurred. (error code=0x%lx)", rc); } BAlert *alert=new BAlert("Error", errMsg, "OK"); alert->Go(); return; } else Quit(); }
void DataTranslationsApplication::RefsReceived(BMessage* message) { BTranslatorRoster* roster = BTranslatorRoster::Default(); BPath path; status_t status = find_directory(B_USER_ADDONS_DIRECTORY, &path, true); if (status != B_OK) { _InstallError("translator", status); return; } BDirectory target; status = target.SetTo(path.Path()); if (status == B_OK) { if (!target.Contains("Translators")) status = target.CreateDirectory("Translators", &target); else status = target.SetTo(&target, "Translators"); } if (status != B_OK) { _InstallError("translator", status); return; } int32 i = 0; entry_ref ref; while (message->FindRef("refs", i++, &ref) == B_OK) { if (!roster->IsTranslator(&ref)) { _NoTranslatorError(ref.name); continue; } BEntry entry(&ref, true); status = entry.InitCheck(); if (status != B_OK) { _InstallError(ref.name, status); continue; } if (target.Contains(ref.name)) { BString string( B_TRANSLATE("An item named '%name' already exists in the " "Translators folder! Shall the existing translator be " "overwritten?")); string.ReplaceAll("%name", ref.name); BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"), string.String(), B_TRANSLATE("Cancel"), B_TRANSLATE("Overwrite")); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() != 1) continue; // the original file will be replaced } // find out whether we need to copy it or not status = _Install(target, entry); if (status == B_OK) { BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"), B_TRANSLATE("The new translator has been installed " "successfully."), B_TRANSLATE("OK")); alert->Go(NULL); } else _InstallError(ref.name, status); } }
void TStatusWindow::MessageReceived(BMessage* msg) { switch (msg->what) { case STATUS: break; case OK: { if (!_Exists(fStatus->Text())) { int32 index = 0; uint32 loop; status_t result; BDirectory dir; BEntry entry; BFile file; BNodeInfo* node; BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); dir.SetTo(path.Path()); if (dir.FindEntry("Mail", &entry) == B_NO_ERROR) dir.SetTo(&entry); else dir.CreateDirectory("Mail", &dir); if (dir.InitCheck() != B_NO_ERROR) goto err_exit; if (dir.FindEntry("status", &entry) == B_NO_ERROR) dir.SetTo(&entry); else dir.CreateDirectory("status", &dir); if (dir.InitCheck() == B_NO_ERROR) { char name[B_FILE_NAME_LENGTH]; char newName[B_FILE_NAME_LENGTH]; sprintf(name, "%s", fStatus->Text()); if (strlen(name) > B_FILE_NAME_LENGTH - 10) name[B_FILE_NAME_LENGTH - 10] = 0; for (loop = 0; loop < strlen(name); loop++) { if (name[loop] == '/') name[loop] = '\\'; } strcpy(newName, name); while (1) { if ((result = dir.CreateFile(newName, &file, true)) == B_NO_ERROR) break; if (result != EEXIST) goto err_exit; sprintf(newName, "%s_%" B_PRId32, name, index++); } dir.FindEntry(newName, &entry); node = new BNodeInfo(&file); node->SetType("text/plain"); delete node; file.Write(fStatus->Text(), strlen(fStatus->Text()) + 1); file.SetSize(file.Position()); file.WriteAttr(INDEX_STATUS, B_STRING_TYPE, 0, fStatus->Text(), strlen(fStatus->Text()) + 1); } } err_exit: { BMessage close(M_CLOSE_CUSTOM); close.AddString("status", fStatus->Text()); fTarget.SendMessage(&close); // will fall through } } case CANCEL: Quit(); break; } }
PApp::PApp() : BApplication("application/x-vnd.dw-PalEdit") { try { try { BPath settings; FailOSErr(find_directory(B_USER_SETTINGS_DIRECTORY, &settings, true)); BDirectory e; FailOSErrMsg(e.SetTo(settings.Path()), "~/config/settings directory not found ?!?!?"); if (!e.Contains("PalEdit", B_DIRECTORY_NODE)) FailOSErr(e.CreateDirectory("PalEdit", &gPrefsDir)); else { BEntry d; FailOSErr(e.FindEntry("PalEdit", &d, B_DIRECTORY_NODE)); FailOSErr(gPrefsDir.SetTo(&d)); } } catch (HErr& e) { e.DoError(); } gPrefs = new HPreferences("PalEdit/settings"); gPrefs->ReadPrefFile(); app_info ai; GetAppInfo(&ai); BEntry entry(&ai.ref); FailOSErr(gAppFile.SetTo(&entry, B_READ_ONLY)); BPath appName; FailOSErr(entry.GetPath(&appName)); BPath dir; FailOSErr(appName.GetParent(&dir)); FailOSErr(gAppDir.SetTo(dir.Path())); fOpenPanel = new BFilePanel(); FailNil(fOpenPanel); entry_ref cwd_ref; fOpenPanel->GetPanelDirectory(&cwd_ref); FailOSErr(gCWD.SetTo(&cwd_ref)); PDoc::LoadAddOns(); InitUTFTables(); SetColor(kColorLow, prf_C_Low, 0xff, 0xff, 0xff); SetColor(kColorText, prf_C_Text, 0x00, 0x00, 0x00); SetColor(kColorSelection, prf_C_Selection, 0xd1, 0xd1, 0xff); SetColor(kColorMark, prf_C_Mark, 0x00, 0x00, 0xff); SetColor(kColorKeyword1, prf_C_Keyword1, 0x00, 0x00, 0xff); SetColor(kColorKeyword2, prf_C_Keyword2, 0x00, 0x00, 0xff); SetColor(kColorComment1, prf_C_Comment1, 0x1e, 0x93, 0x1e); SetColor(kColorComment2, prf_C_Comment2, 0x1e, 0x93, 0x1e); SetColor(kColorString1, prf_C_String1, 0x7e, 0x7e, 0x7e); SetColor(kColorString2, prf_C_String2, 0x7e, 0x7e, 0x7e); SetColor(kColorNumber1, prf_C_Number1, 0x85, 0x0a, 0x48); SetColor(kColorNumber2, prf_C_Number2, 0x85, 0x0a, 0x48); SetColor(kColorOperator1, prf_C_Operator1, 0x00, 0x00, 0x00); SetColor(kColorOperator2, prf_C_Operator2, 0x00, 0x00, 0x00); SetColor(kColorSeparator1, prf_C_Separator1, 0x00, 0x00, 0x00); SetColor(kColorSeparator2, prf_C_Separator2, 0x00, 0x00, 0x00); SetColor(kColorPreprocessor1, prf_C_Preprocessor1, 0x00, 0x00, 0xff); SetColor(kColorPreprocessor2, prf_C_Preprocessor2, 0x00, 0x00, 0xff); SetColor(kColorError1, prf_C_Error1, 0xff, 0x00, 0x00); SetColor(kColorError2, prf_C_Error2, 0xff, 0x00, 0x00); SetColor(kColorIdentifierSystem,prf_C_IdentifierSystem, 0x39, 0x79, 0x79); SetColor(kColorCharConst, prf_C_CharConst, 0x7e, 0x7e, 0x7e); SetColor(kColorIdentifierUser, prf_C_IdentifierUser, 0x00, 0x00, 0x00); SetColor(kColorTag, prf_C_Tag, 0x88, 0x88, 0x88); SetColor(kColorAttribute, prf_C_Attribute, 0xff, 0x00, 0x00); SetColor(kColorUserSet1, prf_C_UserSet1, 0x00, 0x00, 0x00); SetColor(kColorUserSet2, prf_C_UserSet2, 0x00, 0x00, 0x00); SetColor(kColorUserSet3, prf_C_UserSet3, 0x00, 0x00, 0x00); SetColor(kColorUserSet4, prf_C_UserSet4, 0x00, 0x00, 0x00); SetColor(kColorInvisibles, prf_C_Invisibles, 0xC8, 0x64, 0x64); DefineInvColors(gColor[kColorSelection]); gAutoIndent = gPrefs->GetPrefInt(prf_I_AutoIndent, 1); gSyntaxColoring = gPrefs->GetPrefInt(prf_I_SyntaxColoring, 1); gSpacesPerTab = gPrefs->GetPrefInt(prf_I_SpacesPerTab, 4); gBalance = gPrefs->GetPrefInt(prf_I_BalanceWhileTyping, 1); gBlockCursor = gPrefs->GetPrefInt(prf_I_BlockCursor, 0); gFlashCursor = gPrefs->GetPrefInt(prf_I_FlashCursor, 1); gSmartBrace = gPrefs->GetPrefInt(prf_I_SmartBraces, 1); gPopupIncludes = gPrefs->GetPrefInt(prf_I_ShowIncludes, 1); gPopupProtos = gPrefs->GetPrefInt(prf_I_ShowPrototypes, 1); gPopupFuncs = gPrefs->GetPrefInt(prf_I_ShowTypes, 1); gPopupSorted = gPrefs->GetPrefInt(prf_I_SortPopup, 0); gRedirectStdErr = gPrefs->GetPrefInt(prf_I_RedirectStdErr, 1); gUseWorksheet = gPrefs->GetPrefInt(prf_I_Worksheet, 0); gRestorePosition = gPrefs->GetPrefInt(prf_I_RestorePosition, 1); gRestoreFont = gPrefs->GetPrefInt(prf_I_RestoreFont, 1); gRestoreSelection = gPrefs->GetPrefInt(prf_I_RestoreSelection, 1); gRestoreScrollbar = gPrefs->GetPrefInt(prf_I_RestoreScrollbar, 1); gRestoreCWD = gPrefs->GetPrefInt(prf_I_RestoreCwd, 1); gSavedState = gPrefs->GetPrefInt(prf_I_SavedState, 1); if (gPrefs->GetIxPrefString(prf_X_Mimetype, 0) == NULL) { gPrefs->SetIxPrefString(prf_X_Mimetype, 0, "text/plain"); gPrefs->SetIxPrefString(prf_X_Mimetype, 1, "text/html"); gPrefs->SetIxPrefString(prf_X_Mimetype, 2, "text/x-source-code"); } strcpy(gTabChar, gPrefs->GetPrefString(prf_S_TabChar, "»")); strcpy(gReturnChar, gPrefs->GetPrefString(prf_S_ReturnChar, "¬")); strcpy(gSpaceChar, gPrefs->GetPrefString(prf_S_SpaceChar, ".")); strcpy(gControlChar, gPrefs->GetPrefString(prf_S_ControlChar, "¿")); gUid = getuid(); gGid = getgid(); gRecentBufferSize = gPrefs->GetPrefInt(prf_I_RecentSize, 10); RestoreRecentMenu(); fFindDialog = DialogCreator<CFindDialog>::CreateDialog("Find", NULL, PDoc::TopWindow()); fFindDialog->Run(); InitSelectedMap(); CLanguageInterface::SetupLanguageInterfaces(); fIsQuitting = false; fPrefsDialog = NULL; CPrefOpener *prefOpener = new CPrefOpener; fPrefOpener = prefOpener->Thread(); if (gUseWorksheet) OpenWorksheet(); // prefOpener->Run(); } catch (HErr& e) { e.DoError(); exit(1); } catch(...) { beep(); exit(1); } } /* PApp::PApp */
void TSignatureWindow::Save() { char name[B_FILE_NAME_LENGTH]; int32 index = 0; status_t result; BDirectory dir; BEntry entry; BNodeInfo *node; BPath path; if (!fFile) { find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); dir.SetTo(path.Path()); if (dir.FindEntry("bemail", &entry) == B_NO_ERROR) dir.SetTo(&entry); else dir.CreateDirectory("bemail", &dir); if (dir.InitCheck() != B_NO_ERROR) goto err_exit; if (dir.FindEntry("signatures", &entry) == B_NO_ERROR) dir.SetTo(&entry); else dir.CreateDirectory("signatures", &dir); if (dir.InitCheck() != B_NO_ERROR) goto err_exit; fFile = new BFile(); while(true) { sprintf(name, "signature_%ld", index++); if ((result = dir.CreateFile(name, fFile, true)) == B_NO_ERROR) break; if (result != EEXIST) goto err_exit; } dir.FindEntry(name, &fEntry); node = new BNodeInfo(fFile); node->SetType("text/plain"); delete node; } fSigView->fTextView->fDirty = false; fFile->Seek(0, 0); fFile->Write(fSigView->fTextView->Text(), fSigView->fTextView->TextLength()); fFile->SetSize(fFile->Position()); fFile->WriteAttr(INDEX_SIGNATURE, B_STRING_TYPE, 0, fSigView->fName->Text(), strlen(fSigView->fName->Text()) + 1); return; err_exit: beep(); (new BAlert("", MDR_DIALECT_CHOICE ( "An error occurred trying to save this signature.", "署名を保存しようとした時にエラーが発生しました。"), MDR_DIALECT_CHOICE ("Sorry","了解")))->Go(); }
void app::CreateDirectory(const char *folder_name) { BDirectory dir; dir.CreateDirectory(folder_name, &dir); }
void TMailApp::ReadyToRun() { // Create needed indices for META:group, META:email, MAIL:draft, // INDEX_SIGNATURE, INDEX_STATUS on the boot volume BVolume volume; BVolumeRoster().GetBootVolume(&volume); fs_create_index(volume.Device(), "META:group", B_STRING_TYPE, 0); fs_create_index(volume.Device(), "META:email", B_STRING_TYPE, 0); fs_create_index(volume.Device(), "MAIL:draft", B_INT32_TYPE, 0); fs_create_index(volume.Device(), INDEX_SIGNATURE, B_STRING_TYPE, 0); fs_create_index(volume.Device(), INDEX_STATUS, B_STRING_TYPE, 0); fs_create_index(volume.Device(), B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0); // Start people queries fPeopleQueryList.Init("META:email=**"); // Load dictionaries BPath indexDir; BPath dictionaryDir; BPath userDictionaryDir; BPath userIndexDir; BPath dataPath; BPath indexPath; BDirectory directory; BEntry entry; // Locate dictionaries directory find_directory(B_SYSTEM_DATA_DIRECTORY, &indexDir, true); indexDir.Append("spell_check"); dictionaryDir = indexDir; //Locate user dictionary directory find_directory(B_USER_CONFIG_DIRECTORY, &userIndexDir, true); userIndexDir.Append("data/spell_check"); userDictionaryDir = userIndexDir; // Create directory if needed directory.CreateDirectory(userIndexDir.Path(), NULL); // Setup directory paths indexDir.Append(kIndexDirectory); dictionaryDir.Append(kDictDirectory); userIndexDir.Append(kIndexDirectory); userDictionaryDir.Append(kDictDirectory); // Create directories if needed directory.CreateDirectory(indexDir.Path(), NULL); directory.CreateDirectory(dictionaryDir.Path(), NULL); directory.CreateDirectory(userIndexDir.Path(), NULL); directory.CreateDirectory(userDictionaryDir.Path(), NULL); dataPath = dictionaryDir; dataPath.Append("words"); // Only Load if Words Dictionary if (BEntry(kWordsPath).Exists() || BEntry(dataPath.Path()).Exists()) { // If "/boot/optional/goodies/words" exists but there is no // system dictionary, copy words if (!BEntry(dataPath.Path()).Exists() && BEntry(kWordsPath).Exists()) { BFile words(kWordsPath, B_READ_ONLY); BFile copy(dataPath.Path(), B_WRITE_ONLY | B_CREATE_FILE); char buffer[4096]; ssize_t size; while ((size = words.Read( buffer, 4096)) > 0) copy.Write(buffer, size); BNodeInfo(©).SetType("text/plain"); } // Load dictionaries directory.SetTo(dictionaryDir.Path()); BString leafName; gUserDict = -1; while (gDictCount < MAX_DICTIONARIES && directory.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { dataPath.SetTo(&entry); indexPath = indexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kMetaphone); indexPath.Append(leafName.String()); gWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), true); indexPath = indexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kExact); indexPath.Append(leafName.String()); gExactWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), false); gDictCount++; } // Create user dictionary if it does not exist dataPath = userDictionaryDir; dataPath.Append("user"); if (!BEntry(dataPath.Path()).Exists()) { BFile user(dataPath.Path(), B_WRITE_ONLY | B_CREATE_FILE); BNodeInfo(&user).SetType("text/plain"); } // Load user dictionary if (BEntry(userDictionaryDir.Path()).Exists()) { gUserDictFile = new BFile(dataPath.Path(), B_WRITE_ONLY | B_OPEN_AT_END); gUserDict = gDictCount; indexPath = userIndexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kMetaphone); indexPath.Append(leafName.String()); gWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), true); indexPath = userIndexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kExact); indexPath.Append(leafName.String()); gExactWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), false); gDictCount++; } } // Create a new window if starting up without any extra arguments. if (!fPrintHelpAndExit && !fWindowCount) { TMailWindow *window; window = NewWindow(); window->Show(); } }
/*! \brief Opens the file with preferences packed into BMessage for reading. * \param[out] out Link to the BFile used to read the preferences from. * \param[in] openMode Defines how the file should be opened. Read / write... * \returns B_OK in case of success. * \note * Whatever was in the "out" variable, will be overwritten. */ status_t OpenFileWithPreferences( BFile* out, uint32 openMode ) { status_t status = B_OK; BPath path; BString sb; BDirectory eventualSettingsDir; // Access the overall settings directory status = find_directory( B_USER_SETTINGS_DIRECTORY, &path, true ); // Create directory if necessary if ( status != B_OK ) { return status; } // Descent to application's settings directory path.Append( "Eventual" ); eventualSettingsDir.SetTo( path.Path() ); status = eventualSettingsDir.InitCheck(); switch ( status ) { case B_ENTRY_NOT_FOUND: // The directory does not exist. Create it! status = eventualSettingsDir.CreateDirectory( path.Path(), &eventualSettingsDir ); if ( status != B_OK ) { /* Panic! */ sb.SetTo( "Error in creating Eventual Settings directory! Error = " ); sb << ( uint32 )status; utl_Deb = new DebuggerPrintout( sb.String() ); return status; } /* I assume at this point the directory is set. */ break; case B_NAME_TOO_LONG: /* Intentional fall-through */ case B_BAD_VALUE: case B_FILE_ERROR: case B_NO_MORE_FDS: utl_Deb = new DebuggerPrintout( "Name is too long, input is invalid or node is busy." ); return status; break; case B_LINK_LIMIT: utl_Deb = new DebuggerPrintout( "Loop is detected in the filesystem!" ); return status; break; case B_BUSY: utl_Deb = new DebuggerPrintout( "The directory does not exist!" ); return status; break; case B_OK: /* Everything went smooth */ break; default: utl_Deb = new DebuggerPrintout( "Unknown error has occurred." ); break; }; /* Anyway, at this point the directory is set, or we have exitted. */ // Descend into preferences file. path.Append( "Preferences" ); out->SetTo( path.Path(), openMode ); if ( ( status = out->InitCheck() ) != B_OK ) { /* Panic! */ return status; } return B_OK; } // <-- end of function OpenFileWithPreferences