ZipSerialize::Properties propertie(const string &file) { map<string, ZipSerialize::Properties>::const_iterator i = properties.find(file); if(i != properties.end()) return i->second; time_t t = time(0); tm *filetime = gmtime(&t); ZipSerialize::Properties prop = { appInfo(), *filetime }; return properties[file] = prop; }
void CalcView::_FetchAppIcon(BBitmap* into) { entry_ref appRef; status_t status = be_roster->FindApp(kSignature, &appRef); if (status == B_OK) { BFile file(&appRef, B_READ_ONLY); BAppFileInfo appInfo(&file); status = appInfo.GetIcon(into, B_MINI_ICON); } if (status != B_OK) memset(into->Bits(), 0, into->BitsLength()); }
bool is_application(BFile& file) { BAppFileInfo appInfo(&file); if (appInfo.InitCheck() != B_OK) return false; char type[B_MIME_TYPE_LENGTH]; if (appInfo.GetType(type) != B_OK || strcasecmp(type, B_APP_MIME_TYPE)) return false; return true; }
QUrl DeclarativeDragItemWithUrl::decodeUri(const QString& uri) { if (uri.startsWith("application://")) { QString desktopFileName = uri.mid(14); QByteArray bytes = desktopFileName.toUtf8(); GObjectScopedPointer<GDesktopAppInfo> appInfo(g_desktop_app_info_new(bytes.constData())); if (appInfo.isNull()) { return QUrl(uri); } QString filePath = QString::fromUtf8(g_desktop_app_info_get_filename(appInfo.data())); return QUrl("file://" + filePath); } else { return QUrl(uri); } }
int main(void) { double height, weight, bmi; appInfo(); height=getHeight(); weight=getWeight(); bmi=bmiCalc(height, weight); bmiReport(bmi); return 0; }
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval) { nsCOMPtr<nsIWindowsRegKey> regKey = do_CreateInstance("@mozilla.org/windows-registry-key;1"); if (!regKey) return NS_ERROR_NOT_AVAILABLE; NS_ConvertASCIItoUTF16 buf(aScheme); #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN // Vista: use new application association interface if (mAppAssoc) { PRUnichar * pResult = nsnull; // We are responsible for freeing returned strings. HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(), AT_URLPROTOCOL, AL_EFFECTIVE, &pResult); if (SUCCEEDED(hr)) { nsCOMPtr<nsIFile> app; nsAutoString appInfo(pResult); CoTaskMemFree(pResult); if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app)))) return NS_OK; } return NS_ERROR_NOT_AVAILABLE; } #endif nsCOMPtr<nsIFile> app; GetDefaultAppInfo(buf, _retval, getter_AddRefs(app)); if (!_retval.Equals(buf)) return NS_OK; // Fall back to full path buf.AppendLiteral("\\shell\\open\\command"); nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, buf, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_FAILED(rv)) return NS_ERROR_NOT_AVAILABLE; rv = regKey->ReadStringValue(EmptyString(), _retval); return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_NOT_AVAILABLE; }
void GraphicsVk::InitInstance() { _apiVersion = Vk2Version(vk::enumerateInstanceVersion()); _instanceLayers = vk::enumerateInstanceLayerProperties(); _instanceExtensions = vk::enumerateInstanceExtensionProperties(); std::vector<char const*> layerNames; std::vector<char const *> extensionNames; if (_validationLevel > ValidationLevel::None) { AppendLayer(layerNames, _instanceLayers, "VK_LAYER_LUNARG_standard_validation"); AppendExtension(extensionNames, _instanceExtensions, VK_EXT_DEBUG_REPORT_EXTENSION_NAME); } AppendExtension(extensionNames, _instanceExtensions, VK_KHR_SURFACE_EXTENSION_NAME); #if defined(_WIN32) AppendExtension(extensionNames, _instanceExtensions, VK_KHR_WIN32_SURFACE_EXTENSION_NAME); #elif defined(linux) AppendExtension(extensionNames, _instanceExtensions, VK_KHR_XLIB_SURFACE_EXTENSION_NAME); #else #error Unsupported platform! #endif vk::ApplicationInfo appInfo(_appName.c_str(), Version2Vk(_appVersion), _engineName.c_str(), Version2Vk(_engineVersion)); vk::InstanceCreateInfo instanceInfo(vk::InstanceCreateFlags(), &appInfo, static_cast<uint32_t>(layerNames.size()), layerNames.data(), static_cast<uint32_t>(extensionNames.size()), extensionNames.data()); vk::DebugReportCallbackCreateInfoEXT debugCBInfo(vk::DebugReportFlagBitsEXT::eWarning | vk::DebugReportFlagBitsEXT::eError, DbgReportFunc, this); if (_validationLevel > ValidationLevel::None) { instanceInfo.pNext = &debugCBInfo; _hostAllocTracker = std::make_unique<HostAllocationTrackerVk>(); } _instance = vk::createInstanceUnique(instanceInfo); _dynamicDispatch.init(*_instance); if (_validationLevel > ValidationLevel::None) { _debugReportCallback = _instance->createDebugReportCallbackEXTUnique(debugCBInfo, AllocationCallbacks(), _dynamicDispatch); } }
void TTracker::RefsReceived(BMessage *message) { OpenSelector selector = kOpen; if (message->HasInt32("launchUsingSelector")) selector = kRunOpenWithWindow; entry_ref handlingApp; if (message->FindRef("handler", &handlingApp) == B_OK) selector = kOpenWith; int32 count; uint32 type; message->GetInfo("refs", &type, &count); switch (selector) { case kRunOpenWithWindow: OpenContainerWindow(0, message, selector); // window adopts model break; case kOpenWith: { // Open With resulted in passing refs and a handler, open the files // with the handling app message->RemoveName("handler"); // have to find out if handling app is the Tracker // if it is, just pass it to the active Tracker, no matter which Tracker // was chosen to handle the refs char signature[B_MIME_TYPE_LENGTH]; signature[0] = '\0'; { BFile handlingNode(&handlingApp, O_RDONLY); BAppFileInfo appInfo(&handlingNode); appInfo.GetSignature(signature); } if (strcasecmp(signature, kTrackerSignature) != 0) { // handling app not Tracker, pass entries to the apps RefsReceived TrackerLaunch(&handlingApp, message, true); break; } // fall thru, opening refs by the Tracker, as if they were double clicked } case kOpen: { // copy over "Poses" messenger so that refs received recipients know // where the open came from BMessage *bundleThis = NULL; BMessenger messenger; if (message->FindMessenger("TrackerViewToken", &messenger) == B_OK) { bundleThis = new BMessage(); bundleThis->AddMessenger("TrackerViewToken", messenger); } for (int32 index = 0; index < count; index++) { entry_ref ref; message->FindRef("refs", index, &ref); const node_ref *nodeToClose = NULL; const node_ref *nodeToSelect = NULL; ssize_t numBytes; message->FindData("nodeRefsToClose", B_RAW_TYPE, index, (const void **)&nodeToClose, &numBytes); message->FindData("nodeRefToSelect", B_RAW_TYPE, index, (const void **)&nodeToSelect, &numBytes); OpenRef(&ref, nodeToClose, nodeToSelect, selector, bundleThis); } delete bundleThis; break; } } }
void ApplicationTypesWindow::_SetType(BMimeType* type, int32 forceUpdate) { bool enabled = type != NULL; bool appFound = true; // update controls if (type != NULL) { if (fCurrentType == *type) { if (!forceUpdate) return; } else forceUpdate = B_EVERYTHING_CHANGED; if (&fCurrentType != type) fCurrentType.SetTo(type->Type()); fSignatureView->SetText(type->Type()); char description[B_MIME_TYPE_LENGTH]; if ((forceUpdate & B_SHORT_DESCRIPTION_CHANGED) != 0) { if (type->GetShortDescription(description) != B_OK) description[0] = '\0'; fNameView->SetText(description); } entry_ref ref; if ((forceUpdate & B_APP_HINT_CHANGED) != 0 && be_roster->FindApp(fCurrentType.Type(), &ref) == B_OK) { // Set launch message BMessenger tracker("application/x-vnd.Be-TRAK"); BMessage* message = new BMessage(B_REFS_RECEIVED); message->AddRef("refs", &ref); fLaunchButton->SetMessage(message); fLaunchButton->SetTarget(tracker); // Set path BPath path(&ref); path.GetParent(&path); fPathView->SetText(path.Path()); // Set "Show In Tracker" message BEntry entry(path.Path()); entry_ref directoryRef; if (entry.GetRef(&directoryRef) == B_OK) { BMessenger tracker("application/x-vnd.Be-TRAK"); message = new BMessage(B_REFS_RECEIVED); message->AddRef("refs", &directoryRef); fTrackerButton->SetMessage(message); fTrackerButton->SetTarget(tracker); } else { fTrackerButton->SetMessage(NULL); appFound = false; } } if (forceUpdate == B_EVERYTHING_CHANGED) { // update version information BFile file(&ref, B_READ_ONLY); if (file.InitCheck() == B_OK) { BAppFileInfo appInfo(&file); version_info versionInfo; if (appInfo.InitCheck() == B_OK && appInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK) { char version[256]; snprintf(version, sizeof(version), "%" B_PRIu32 ".%" B_PRIu32 ".%" B_PRIu32 ", %s/%" B_PRIu32, versionInfo.major, versionInfo.middle, versionInfo.minor, variety_to_text(versionInfo.variety), versionInfo.internal); fVersionView->SetText(version); fDescriptionView->SetText(versionInfo.long_info); } else { fVersionView->SetText(NULL); fDescriptionView->SetText(NULL); } } } } else { fNameView->SetText(NULL); fSignatureView->SetText(NULL); fPathView->SetText(NULL); fVersionView->SetText(NULL); fDescriptionView->SetText(NULL); } fNameView->SetEnabled(enabled); fSignatureView->SetEnabled(enabled); fPathView->SetEnabled(enabled); fVersionView->SetEnabled(enabled); fDescriptionLabel->SetEnabled(enabled); fTrackerButton->SetEnabled(enabled && appFound); fLaunchButton->SetEnabled(enabled && appFound); fEditButton->SetEnabled(enabled && appFound); }
int main() { // first, create a vulkan instance // the needed/used instance extensions constexpr const char* iniExtensions[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_EXTENSION_NAME }; // enables all default layers constexpr auto layer = "VK_LAYER_LUNARG_standard_validation"; // basic application info // we use vulkan api version 1.0 vk::ApplicationInfo appInfo ("vpp-intro", 1, "vpp", 1, VK_API_VERSION_1_0); vk::InstanceCreateInfo instanceInfo; instanceInfo.pApplicationInfo = &appInfo; instanceInfo.enabledExtensionCount = sizeof(iniExtensions) / sizeof(iniExtensions[0]); instanceInfo.ppEnabledExtensionNames = iniExtensions; instanceInfo.enabledLayerCount = 1; instanceInfo.ppEnabledLayerNames = &layer; vpp::Instance instance(instanceInfo); // create a debug callback for our instance and the default layers // the default implementation will just output to std::cerr when a debug callback // is received vpp::DebugCallback debugCallback(instance); // this function will create a winapi window wrapper and also create a surface for it // this should usually be done by a cross platform window abstraction Window window(instance); // now create a device for the instance and surface // note how vpp will automatically select a suited physical device and query // queue families to create basic-needs queues with this constructor. // We also retrieve the present queue to present on our surface from this // constructor const vpp::Queue* presentQueue; vpp::Device device(instance, window.surface, presentQueue); // now we can create a vulkan swapchain // again, we just use the fast way that choses quite sane defaults for us but note // that the class offers many convininient configuration possibilities vpp::Swapchain swapchain(device, window.surface); // to render the triangle we also need to create a render pass vpp::RenderPass renderPass = createRenderPass(swapchain); // we also create the graphics pipeline that will render our triangle as well // as the buffer to hold our vertices vpp::PipelineLayout pipelineLayout(device, {}); auto pipeline = createGraphicsPipeline(device, renderPass, pipelineLayout); // note how vpp takes care of buffer allocation (in an efficient way, even when used // for multiple resources) constexpr auto size = 3u * (2u + 4u) * 4u; // 3 vertices, vec2, vec4 with 4 bytes components constexpr auto usage = vk::BufferUsageBits::vertexBuffer | vk::BufferUsageBits::transferDst; vpp::Buffer vertexBuffer(device, {{}, size, usage}); // vertex data (only positions and color) constexpr std::array<float, 6 * 3> vertexData = {{ 0.f, -0.75f, 1.f, 0.f, 0.f, 1.f, // top -0.75f, 0.75f, 0.f, 1.f, 0.f, 1.f, // left 0.75f, 0.75f, 0.f, 0.f, 1.f, 1.f // right }}; // vpp can now be used to fill the vertex buffer with data in the most efficient way // in this case the buffer layout does not matter since its a vertex buffer // note how vpp automatically unpacks the std::array vpp::fill140(vertexBuffer, vpp::raw(vertexData)); // to render onto the created swapchain we can use vpp::SwapchainRenderer // the class implements the default framebuffer and commandbuffer handling // we simply implement the vpp::RendererBuilder interface that will be used // to build the render command buffers vpp::SwapchainRenderer::CreateInfo rendererInfo; rendererInfo.queueFamily = device.queue(vk::QueueBits::graphics)->family(); rendererInfo.renderPass = renderPass; auto impl = std::make_unique<IntroRendererImpl>(); impl->pipeline = pipeline; impl->vertexBuffer = vertexBuffer; vpp::SwapchainRenderer renderer(swapchain, rendererInfo, std::move(impl)); renderer.record(); // run the main loop // we just recevie windows events and render after all are processed // sry for windows again... using Clock = std::chrono::high_resolution_clock; auto frames = 0u; auto point = Clock::now(); auto run = true; while(run) { MSG msg; while(PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE) != 0) { if(msg.message == WM_QUIT) { run = false; break; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } if(!run) break; renderer.renderBlock(*presentQueue); ++frames; // output the average fps count ever second auto duration = Clock::now() - point; if(duration >= std::chrono::seconds(1)) { auto count = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); std::cout << static_cast<int>(frames * (1000.0 / count)) << " fps\n"; point = Clock::now(); frames = 0u; } } return EXIT_SUCCESS; }
void TTracker::RefsReceived(BMessage* message) { OpenSelector selector = kOpen; if (message->HasInt32("launchUsingSelector")) selector = kRunOpenWithWindow; entry_ref handlingApp; if (message->FindRef("handler", &handlingApp) == B_OK) selector = kOpenWith; int32 count; uint32 type; message->GetInfo("refs", &type, &count); switch (selector) { case kRunOpenWithWindow: OpenContainerWindow(0, message, selector); // window adopts model break; case kOpenWith: { // Open With resulted in passing refs and a handler, // open the files with the handling app message->RemoveName("handler"); // have to find out if handling app is the Tracker // if it is, just pass it to the active Tracker, // no matter which Tracker was chosen to handle the refs char signature[B_MIME_TYPE_LENGTH]; signature[0] = '\0'; { BFile handlingNode(&handlingApp, O_RDONLY); BAppFileInfo appInfo(&handlingNode); appInfo.GetSignature(signature); } if (strcasecmp(signature, kTrackerSignature) != 0) { // handling app not Tracker, pass entries to the apps // RefsReceived TrackerLaunch(&handlingApp, message, true); break; } } // fall thru, opening refs by the Tracker as if they were // double-clicked case kOpen: { // copy over "Poses" messenger so that refs received // recipients know where the open came from BMessage* bundleThis = NULL; BMessage stackBundleThis; BMessenger messenger; if (message->FindMessenger("TrackerViewToken", &messenger) == B_OK) { bundleThis = &stackBundleThis; bundleThis->AddMessenger("TrackerViewToken", messenger); } else { // copy over any "be:*" fields -- e.g. /bin/open may include // "be:line" and "be:column" for (int32 i = 0;; i++) { char* name; type_code type; int32 count; status_t error = message->GetInfo(B_ANY_TYPE, i, &name, &type, &count); if (error != B_OK) break; if (strncmp(name, "be:", 3) != 0) continue; for (int32 k = 0; k < count; k++) { const void* data; ssize_t size; if (message->FindData(name, type, k, &data, &size) != B_OK) { break; } if (stackBundleThis.AddData(name, type, data, size) != B_OK) { break; } bundleThis = &stackBundleThis; } } } for (int32 index = 0; index < count; index++) { entry_ref ref; message->FindRef("refs", index, &ref); const node_ref* nodeToClose = NULL; const node_ref* nodeToSelect = NULL; ssize_t numBytes; message->FindData("nodeRefsToClose", B_RAW_TYPE, index, (const void**)&nodeToClose, &numBytes); message->FindData("nodeRefToSelect", B_RAW_TYPE, index, (const void**)&nodeToSelect, &numBytes); OpenRef(&ref, nodeToClose, nodeToSelect, selector, bundleThis); } break; } } }
int main() { constexpr auto width = 1200u; constexpr auto height = 800u; // init ny app auto& backend = ny::Backend::choose(); if(!backend.vulkan()) { dlg_error("ny backend has no vulkan support!"); return 0; } auto ac = backend.createAppContext(); // basic vpp init auto iniExtensions = ac->vulkanExtensions(); iniExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); vk::ApplicationInfo appInfo ("vpp-intro", 1, "vpp", 1, VK_API_VERSION_1_0); vk::InstanceCreateInfo instanceInfo; instanceInfo.pApplicationInfo = &appInfo; instanceInfo.enabledExtensionCount = iniExtensions.size(); instanceInfo.ppEnabledExtensionNames = iniExtensions.data(); #ifdef WithLayers constexpr auto layer = "VK_LAYER_LUNARG_standard_validation"; instanceInfo.enabledLayerCount = 1; instanceInfo.ppEnabledLayerNames = &layer; #endif vpp::Instance instance(instanceInfo); #ifdef WithLayers vpp::DebugCallback debugCallback(instance); #endif // ny init auto run = true; auto listener = MyWindowListener {}; listener.run = &run; auto vkSurface = vk::SurfaceKHR {}; auto ws = ny::WindowSettings {}; ws.surface = ny::SurfaceType::vulkan; ws.listener = &listener; ws.size = {width, height}; ws.vulkan.instance = (VkInstance) instance.vkHandle(); ws.vulkan.storeSurface = &(std::uintptr_t&) (vkSurface); auto wc = ac->createWindowContext(ws); // further vpp init const vpp::Queue* presentQueue; vpp::Device device(instance, vkSurface, presentQueue); vpp::Swapchain swapchain(device, vkSurface, {width, height}, {}); // vvg setup auto nvgContext = vvg::createContext(swapchain); auto font = nvgCreateFont(nvgContext, "sans", "Roboto-Regular.ttf"); using Clock = std::chrono::high_resolution_clock; auto lastFrameTimer = Clock::now(); unsigned int framesCount = 0; std::string fpsString = "420 fps"; // main loop while(run) { if(!ac->dispatchEvents()) break; nvgBeginFrame(nvgContext, width, height, width / (float) height); nvgBeginPath(nvgContext); nvgMoveTo(nvgContext, 10, 10); nvgLineTo(nvgContext, 10, 400); nvgLineTo(nvgContext, 100, 400); nvgQuadTo(nvgContext, 100, 50, 400, 120); nvgLineTo(nvgContext, 450, 10); nvgClosePath(nvgContext); nvgFillColor(nvgContext, nvgRGBAf(0.5, 0.8, 0.7, 1.0)); nvgFill(nvgContext); nvgBeginPath(nvgContext); nvgFontFaceId(nvgContext, font); nvgFontSize(nvgContext, 100.f); nvgFontBlur(nvgContext, .8f); nvgFillColor(nvgContext, nvgRGBAf(1.0, 1.0, 1.0, 1.0)); nvgTextBox(nvgContext, 200, 200, width - 200, "Hello Vulkan Vector Graphics World", nullptr); nvgFontSize(nvgContext, 30.f); nvgFontBlur(nvgContext, .2f); nvgText(nvgContext, 10, height - 20, fpsString.c_str(), nullptr); nvgBeginPath(nvgContext); nvgRect(nvgContext, 700, 400, 300, 300); nvgPathWinding(nvgContext, NVG_HOLE); nvgRect(nvgContext, 750, 450, 50, 50); // auto paint = nvgRadialGradient(nvgContext, 750, 425,20, 50, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0)); // auto paint = nvgRadialGradient(nvgContext, 0.0, 0.0, 0.2, 100.0, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0)); auto paint = nvgLinearGradient(nvgContext, 700, 400, 800, 450, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0)); nvgFillPaint(nvgContext, paint); // nvgFillColor(nvgContext, nvgRGBA(200, 200, 0, 200)); nvgClosePath(nvgContext); nvgFill(nvgContext); nvgEndFrame(nvgContext); // only refresh frame timer every second framesCount++; if(Clock::now() - lastFrameTimer >= std::chrono::seconds(1)) { fpsString = std::to_string(framesCount) + " fps"; lastFrameTimer = Clock::now(); framesCount = 0; } } vvg::destroyContext(*nvgContext); }
status_t CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir) { if (ref == NULL) return B_BAD_VALUE; BNode typeNode; BFile file; status_t status = file.SetTo(ref, B_READ_ONLY); if (status < B_OK) return status; bool isDir = file.IsDirectory(); if (_entryIsDir != NULL) *_entryIsDir = isDir; if (isDir) return B_OK; BAppFileInfo appInfo(&file); status = appInfo.InitCheck(); if (status < B_OK) return status; // Read the app sig (which consequently keeps us from updating // non-applications, since we get an error if the file has no // app sig) BString signature; status = file.ReadAttrString("BEOS:APP_SIG", &signature); if (status < B_OK) return B_BAD_TYPE; // Init our various objects BMimeType mime; status = mime.SetTo(signature.String()); if (status < B_OK) return status; InstallNotificationDeferrer _(fDatabase, signature.String()); if (!mime.IsInstalled()) mime.Install(); BString path = "/"; path.Append(signature); path.ToLower(); // Signatures and MIME types are case insensitive, but we want to // preserve the case wherever possible path.Prepend(get_database_directory().c_str()); status = typeNode.SetTo(path.String()); if (status < B_OK) return status; // Preferred App attr_info info; if (status == B_OK && (fForce || typeNode.GetAttrInfo(kPreferredAppAttr, &info) != B_OK)) status = mime.SetPreferredApp(signature.String()); // Short Description (name of the application) if (status == B_OK && (fForce || typeNode.GetAttrInfo(kShortDescriptionAttr, &info) != B_OK)) status = mime.SetShortDescription(ref->name); // App Hint if (status == B_OK && (fForce || typeNode.GetAttrInfo(kAppHintAttr, &info) != B_OK)) status = mime.SetAppHint(ref); // Vector Icon if (status == B_OK && (fForce || typeNode.GetAttrInfo(kIconAttr, &info) != B_OK)) { uint8* data = NULL; size_t size = 0; if (appInfo.GetIcon(&data, &size) == B_OK) { status = mime.SetIcon(data, size); free(data); } } // Mini Icon BBitmap miniIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK, B_CMAP8); if (status == B_OK && (fForce || typeNode.GetAttrInfo(kMiniIconAttr, &info) != B_OK)) { if (appInfo.GetIcon(&miniIcon, B_MINI_ICON) == B_OK) status = mime.SetIcon(&miniIcon, B_MINI_ICON); } // Large Icon BBitmap largeIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_CMAP8); if (status == B_OK && (fForce || typeNode.GetAttrInfo(kLargeIconAttr, &info) != B_OK)) { if (appInfo.GetIcon(&largeIcon, B_LARGE_ICON) == B_OK) status = mime.SetIcon(&largeIcon, B_LARGE_ICON); } // Supported Types bool setSupportedTypes = false; BMessage supportedTypes; if (status == B_OK && (fForce || typeNode.GetAttrInfo(kSupportedTypesAttr, &info) != B_OK)) { if (appInfo.GetSupportedTypes(&supportedTypes) == B_OK) setSupportedTypes = true; } // defer notifications for supported types const char* type; for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) fDatabase->DeferInstallNotification(type); // set supported types if (setSupportedTypes) status = mime.SetSupportedTypes(&supportedTypes); // Icons for supported types for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) { // vector icon uint8* data = NULL; size_t size = 0; if (status == B_OK && appInfo.GetIconForType(type, &data, &size) == B_OK) { status = mime.SetIconForType(type, data, size); free(data); } // mini icon if (status == B_OK && appInfo.GetIconForType(type, &miniIcon, B_MINI_ICON) == B_OK) status = mime.SetIconForType(type, &miniIcon, B_MINI_ICON); // large icon if (status == B_OK && appInfo.GetIconForType(type, &largeIcon, B_LARGE_ICON) == B_OK) status = mime.SetIconForType(type, &largeIcon, B_LARGE_ICON); } // undefer notifications for supported types for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) fDatabase->UndeferInstallNotification(type); return status; }
int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; atexit(safeExit); // init log system gp_log_init(APP_LOGFILE); // Get some application/host data appInfo(); /* if (isAppRunning()) { printf("Application is already running\n"); exit(0); g_critical("Application is already running"); } */ // parse command line arguments context = g_option_context_new (APP_DESCRIPTION); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } // enable verbose mode if (opt_verbose) { gp_log_set_verbose(TRUE); } g_message("Program start\n"); // print version information if (opt_version) { printf("Program version %s\nBuild ("__DATE__" "__TIME__")\n", APP_VERSION); exit(0); } // Error Test if (opt_errorTest) { errorTest(); exit(0); } // thread test if (opt_threadTest) { threadTest(); exit(0); } // info test if (opt_info) { infoTest(); exit(0); } // daemon test if (opt_daemonTest) { daemonTest(); exit(0); } // queue test if (opt_queueTest) { queueTest(); exit(0); } // pipe test if (opt_pipeTest) { pipeTest(); exit(0); } // domain socket test if (opt_domainTest) { domainTest(); exit(0); } return 0; }
status_t retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType, BString& preferredApp) { entry_ref ref; if (message == NULL || message->FindRef("refs", &ref) != B_OK) return B_BAD_VALUE; BFile file(&ref, B_READ_ONLY); status_t status = file.InitCheck(); char preferred[B_MIME_TYPE_LENGTH]; if (status == B_OK) { if (sameAs) { // get preferred app from file BNodeInfo nodeInfo(&file); status = nodeInfo.InitCheck(); if (status == B_OK) { if (nodeInfo.GetPreferredApp(preferred) != B_OK) preferred[0] = '\0'; if (!preferred[0]) { // get MIME type from file char type[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(type) == B_OK) { BMimeType mimeType(type); mimeType.GetPreferredApp(preferred); } } } } else { // get application signature BAppFileInfo appInfo(&file); status = appInfo.InitCheck(); if (status == B_OK && appInfo.GetSignature(preferred) != B_OK) preferred[0] = '\0'; } } if (status != B_OK) { error_alert(B_TRANSLATE("File could not be opened"), status, B_STOP_ALERT); return status; } if (!preferred[0]) { error_alert(sameAs ? B_TRANSLATE("Could not retrieve preferred application of this " "file") : B_TRANSLATE("Could not retrieve application signature")); return B_ERROR; } // Check if the application chosen supports this type BMimeType mimeType(forType); bool found = false; BMessage applications; if (mimeType.GetSupportingApps(&applications) == B_OK && is_application_in_message(applications, preferred)) found = true; applications.MakeEmpty(); if (!found && mimeType.GetWildcardApps(&applications) == B_OK && is_application_in_message(applications, preferred)) found = true; if (!found) { // warn user BMimeType appType(preferred); char description[B_MIME_TYPE_LENGTH]; if (appType.GetShortDescription(description) != B_OK) description[0] = '\0'; char warning[512]; snprintf(warning, sizeof(warning), B_TRANSLATE("The application " "\"%s\" does not support this file type.\n" "Are you sure you want to set it anyway?"), description[0] ? description : preferred); BAlert* alert = new BAlert(B_TRANSLATE("FileTypes request"), warning, B_TRANSLATE("Set Preferred Application"), B_TRANSLATE("Cancel"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); if (alert->Go() == 1) return B_ERROR; } preferredApp = preferred; return B_OK; }