Esempio n. 1
0
void
DockItem::GetGenericIcon( void )
{
	if ( IsFolder() ) {
		BMimeType type;
		type.SetType( "application/x-vnd.Be-directory" );
		type.GetIcon( mLargeIcon, B_LARGE_ICON );
		type.GetIcon( mSmallIcon, B_MINI_ICON );
	} else {
		app_info appInfo;
		BFile appFile;
		BAppFileInfo appFileInfo;
		be_app->GetAppInfo( &appInfo );
		appFile.SetTo( &appInfo.ref, B_READ_WRITE );
		appFileInfo.SetTo( &appFile );
		appFileInfo.GetIconForType( "application/x-be-executable", mLargeIcon, B_LARGE_ICON );
		appFileInfo.GetIconForType( "application/x-be-executable", mSmallIcon, B_MINI_ICON );
		/*
		BMimeType appType;
		appType.SetType( "application/x-vnd.HK-LaunchPad" );
		appType.GetIcon( mLargeIcon, B_LARGE_ICON );
		appType.GetIcon( mSmallIcon, B_MINI_ICON );
		*/
	}
}
Esempio n. 2
0
		BString version() {
			app_info appInfo;
			BFile file;
			BAppFileInfo appFileInfo;

			be_app->GetAppInfo(&appInfo);
			file.SetTo(&appInfo.ref, B_READ_WRITE);
			appFileInfo.SetTo(&file);

			BString version;

			version_info info;
			appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND);
			version << info.major;
			version << '.';
			version << info.middle;
			version << '.';
			version << info.minor;

			switch(info.variety)
			{
				case B_BETA_VERSION:
					version << "\xCE\xB2";
			}

			if(info.internal > 0) {
				version << info.internal;
			}

			return version;
		}	
Esempio n. 3
0
// create_app
static
entry_ref
create_app(const char *filename, const char *signature,
		   bool install = false, bool makeExecutable = true,
		   uint32 appFlags = B_SINGLE_LAUNCH)
{
	BString testApp;
	CHK(find_test_app("RosterBroadcastTestApp1", &testApp) == B_OK);
	system((string("cp ") + testApp.String() + " " + filename).c_str());
	if (makeExecutable)
		system((string("chmod a+x ") + filename).c_str());
	BFile file;
	CHK(file.SetTo(filename, B_READ_WRITE) == B_OK);
	BAppFileInfo appFileInfo;
	CHK(appFileInfo.SetTo(&file) == B_OK);
	if (signature)
		CHK(appFileInfo.SetSignature(signature) == B_OK);
	CHK(appFileInfo.SetAppFlags(appFlags) == B_OK);
	if (install && signature)
		CHK(BMimeType(signature).Install() == B_OK);
	// We write the signature into a separate attribute, just in case we
	// decide to also test files without BEOS:APP_SIG attribute.
	BString signatureString(signature);
	file.WriteAttrString("signature", &signatureString);
	return ref_for_path(filename);
}
Esempio n. 4
0
void
Icon::SetTo(const BAppFileInfo& info, const char* type)
{
	Unset();

	uint8* data;
	size_t size;
	if (info.GetIconForType(type, &data, &size) == B_OK) {
		// we have the vector icon, no need to get the rest
		AdoptData(data, size);
		return;
	}

	BBitmap* icon = AllocateBitmap(B_LARGE_ICON, B_CMAP8);
	if (icon && info.GetIconForType(type, icon, B_LARGE_ICON) == B_OK)
		AdoptLarge(icon);
	else
		delete icon;

	icon = AllocateBitmap(B_MINI_ICON, B_CMAP8);
	if (icon && info.GetIconForType(type, icon, B_MINI_ICON) == B_OK)
		AdoptMini(icon);
	else
		delete icon;
}
Esempio n. 5
0
ArpDocumentButton::ArpDocumentButton(BRect frame, const char *name, BBitmap* icon,
									 BMessage* pressMsg,
									 uint32 resizeMask, uint32 flags)
	: BControl(frame, name, "", pressMsg, resizeMask, flags),
	  mDocIcon(icon), mSmallIcon(0),
	  mAction(Inactive),
	  mPressed(false), mMenued(false), mDropped(false)
{
	SetHandlerForReply(this);
	
	if( mDocIcon == 0 ) {
		app_info ai;
		BFile file;
		BAppFileInfo afi;
		be_app->GetAppInfo(&ai);
		file.SetTo(&ai.ref, B_READ_ONLY);
		afi.SetTo(&file);
		mDocIcon = new BBitmap(BRect(0,0,15,15), B_CMAP8);
		if( afi.GetIcon(mDocIcon, B_MINI_ICON) != B_OK ) {
			delete mDocIcon;
			mDocIcon = 0;
		}
	}
	
	mSmallIcon = BTranslationUtils::GetBitmap('bmp ', 1);
		
}
Esempio n. 6
0
void
GetAppVersion( version_info* version )
{
	// Get version_info for be_app
	app_info		ai;
	BFile			file;
	BAppFileInfo	afi;
	be_app->GetAppInfo(&ai); 
	file.SetTo(&ai.ref, B_READ_WRITE); 
	afi.SetTo(&file);
	afi.GetVersionInfo( version, B_APP_VERSION_KIND );
}
Esempio n. 7
0
status_t
Icon::CopyTo(BAppFileInfo& info, const char* type, bool force) const
{
	status_t status = B_OK;

	if (fLarge != NULL || force)
		status = info.SetIconForType(type, fLarge, B_LARGE_ICON);
	if (fMini != NULL || force)
		status = info.SetIconForType(type, fMini, B_MINI_ICON);
	if (fData != NULL || force)
		status = info.SetIconForType(type, fData, fSize);
	return status;
}
Esempio n. 8
0
void
IconView::Update()
{
	delete fIcon;
	fIcon = NULL;

	Invalidate();
		// this will actually trigger a redraw *after* we updated the icon below

	BBitmap* icon = NULL;

	if (fHasRef) {
		BFile file(&fRef, B_READ_ONLY);
		if (file.InitCheck() != B_OK)
			return;

		BAppFileInfo info;
		if (info.SetTo(&file) != B_OK)
			return;

		icon = Icon::AllocateBitmap(fIconSize);
		if (icon != NULL && info.GetIconForType(fType.Type(), icon,
				(icon_size)fIconSize) != B_OK) {
			delete icon;
			return;
		}
	} else if (fHasType) {
		icon = Icon::AllocateBitmap(fIconSize);
		if (icon != NULL && icon_for_type(fType, *icon, (icon_size)fIconSize,
				&fSource) != B_OK) {
			delete icon;
			return;
		}
	} else if (fIconData) {
		icon = Icon::AllocateBitmap(fIconSize);
		if (fIconData->GetIcon(icon) != B_OK) {
			delete icon;
			icon = NULL;
		}
	}

	fIcon = icon;
}
Esempio n. 9
0
void get_app_info(team_id team, BBitmap **icon, char **name)
{
	app_info info;

	if (be_roster->GetRunningAppInfo(team, &info) == B_BAD_TEAM_ID) {
		*icon = NULL;
		*name = NULL;
		return;
	}
	
	*name = strdup(info.ref.name);
	BFile file;
	BAppFileInfo afi;
	
	file.SetTo(&info.ref, B_READ_ONLY);
	afi.SetTo(&file);
	*icon = new BBitmap(BRect(0.0,0.0,15.0,15.0), B_CMAP8);
	if (!*icon) {return;}
	if (afi.GetIcon(*icon, B_MINI_ICON) != B_NO_ERROR)
		{*icon = NULL; return;}
}
Esempio n. 10
0
bool BeAIMApplication::SetDeskbarVisibility( bool vis )
{
	app_info appInfo;
	BFile file;
	BAppFileInfo appFileInfo;
	uint32 appFlags;

	// get the BAppFileInfo object for this application
	be_app->GetAppInfo(&appInfo);
	file.SetTo(&appInfo.ref, B_READ_WRITE);
	appFileInfo.SetTo(&file);

	// get the app flags
	appFileInfo.GetAppFlags(&appFlags);

	// make the app visible (or not) in the deskbar
	if( vis )
		appFlags &= ~B_BACKGROUND_APP;
	else
		appFlags |= B_BACKGROUND_APP;

	// now set them!
	appFileInfo.SetAppFlags(appFlags);
}
Esempio n. 11
0
void
ShutdownProcess::_AddShutdownWindowApps(AppInfoList& infos)
{
	if (!fHasGUI)
		return;

	for (AppInfoList::Iterator it = infos.It(); it.IsValid(); ++it) {
		RosterAppInfo* info = *it;

		// init an app file info
		BFile file;
		status_t error = file.SetTo(&info->ref, B_READ_ONLY);
		if (error != B_OK) {
			WARNING(("ShutdownProcess::_AddShutdownWindowApps(): Failed to "
				"open file for app %s: %s\n", info->signature,
				strerror(error)));
			continue;
		}

		BAppFileInfo appFileInfo;
		error = appFileInfo.SetTo(&file);
		if (error != B_OK) {
			WARNING(("ShutdownProcess::_AddShutdownWindowApps(): Failed to "
				"init app file info for app %s: %s\n", info->signature,
				strerror(error)));
		}

		// get the application icons
#ifdef __HAIKU__
		color_space format = B_RGBA32;
#else
		color_space format = B_CMAP8;
#endif

		// mini icon
		BBitmap* miniIcon = new(nothrow) BBitmap(BRect(0, 0, 15, 15), format);
		if (miniIcon != NULL) {
			error = miniIcon->InitCheck();
			if (error == B_OK)
				error = appFileInfo.GetTrackerIcon(miniIcon, B_MINI_ICON);
			if (error != B_OK) {
				delete miniIcon;
				miniIcon = NULL;
			}
		}

		// mini icon
		BBitmap* largeIcon = new(nothrow) BBitmap(BRect(0, 0, 31, 31), format);
		if (largeIcon != NULL) {
			error = largeIcon->InitCheck();
			if (error == B_OK)
				error = appFileInfo.GetTrackerIcon(largeIcon, B_LARGE_ICON);
			if (error != B_OK) {
				delete largeIcon;
				largeIcon = NULL;
			}
		}

		// add the app
		error = fWindow->AddApp(info->team, miniIcon, largeIcon);
		if (error != B_OK) {
			WARNING(("ShutdownProcess::_AddShutdownWindowApps(): Failed to "
				"add app to the shutdown window: %s\n", strerror(error)));
		}
	}
}
Esempio n. 12
0
AboutView::AboutView()
	: BView("aboutview", B_WILL_DRAW | B_PULSE_NEEDED),
	fLastActionTime(system_time()),
	fScrollRunner(NULL)
{
	// Begin Construction of System Information controls

	system_info systemInfo;
	get_system_info(&systemInfo);

	// Create all the various labels for system infomation

	// OS Version

	char string[1024];
	strcpy(string, B_TRANSLATE("Unknown"));

	// the version is stored in the BEOS:APP_VERSION attribute of libbe.so
	BPath path;
	if (find_directory(B_BEOS_LIB_DIRECTORY, &path) == B_OK) {
		path.Append("libbe.so");

		BAppFileInfo appFileInfo;
		version_info versionInfo;
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
			&& appFileInfo.SetTo(&file) == B_OK
			&& appFileInfo.GetVersionInfo(&versionInfo,
				B_APP_VERSION_KIND) == B_OK
			&& versionInfo.short_info[0] != '\0')
			strcpy(string, versionInfo.short_info);
	}

	// Add revision from uname() info
	utsname unameInfo;
	if (uname(&unameInfo) == 0) {
		long revision;
		if (sscanf(unameInfo.version, "r%ld", &revision) == 1) {
			char version[16];
			snprintf(version, sizeof(version), "%ld", revision);
			strlcat(string, " (", sizeof(string));
			strlcat(string, B_TRANSLATE("Revision"), sizeof(string));
			strlcat(string, " ", sizeof(string));
			strlcat(string, version, sizeof(string));
			strlcat(string, ")", sizeof(string));
		}
	}

	BStringView* versionView = new BStringView("ostext", string);
	versionView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// GCC version
	BEntry gccFourHybrid("/boot/system/lib/gcc2/libstdc++.r4.so");
	BEntry gccTwoHybrid("/boot/system/lib/gcc4/libsupc++.so");
	if (gccFourHybrid.Exists() || gccTwoHybrid.Exists())
		snprintf(string, sizeof(string), B_TRANSLATE("GCC %d Hybrid"),
			__GNUC__);
	else
		snprintf(string, sizeof(string), "GCC %d", __GNUC__);

	BStringView* gccView = new BStringView("gcctext", string);
	gccView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// CPU count, type and clock speed
	char processorLabel[256];
	if (systemInfo.cpu_count > 1) {
		snprintf(processorLabel, sizeof(processorLabel),
			B_TRANSLATE("%ld Processors:"), systemInfo.cpu_count);
	} else
		strlcpy(processorLabel, B_TRANSLATE("Processor:"),
			sizeof(processorLabel));

	BString cpuType;
	cpuType << get_cpu_vendor_string(systemInfo.cpu_type)
		<< " " << get_cpu_model_string(&systemInfo);

	BStringView* cpuView = new BStringView("cputext", cpuType.String());
	cpuView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	int32 clockSpeed = get_rounded_cpu_speed();
	if (clockSpeed < 1000)
		sprintf(string, B_TRANSLATE("%ld MHz"), clockSpeed);
	else
		sprintf(string, B_TRANSLATE("%.2f GHz"), clockSpeed / 1000.0f);

	BStringView* frequencyView = new BStringView("frequencytext", string);
	frequencyView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// RAM
	BStringView *memSizeView = new BStringView("ramsizetext",
		MemSizeToString(string, sizeof(string), &systemInfo));
	memSizeView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));
	fMemView = new BStringView("ramtext",
		MemUsageToString(string, sizeof(string), &systemInfo));
	fMemView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// Kernel build time/date
	snprintf(string, sizeof(string), "%s %s",
		systemInfo.kernel_build_date, systemInfo.kernel_build_time);

	BStringView* kernelView = new BStringView("kerneltext", string);
	kernelView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// Uptime
	fUptimeView = new BTextView("uptimetext");
	fUptimeView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	fUptimeView->MakeEditable(false);
	fUptimeView->MakeSelectable(false);
	fUptimeView->SetWordWrap(true);

	fUptimeView->SetText(UptimeToString(string, sizeof(string)));

	const float offset = 5;

	SetLayout(new BGroupLayout(B_HORIZONTAL));

	BLayoutBuilder::Group<>((BGroupLayout*)GetLayout())
		.AddGroup(B_VERTICAL)
			.Add(new LogoView())
			.AddGroup(B_VERTICAL)
				.Add(_CreateLabel("oslabel", B_TRANSLATE("Version:")))
				.Add(versionView)
				.Add(gccView)
				.AddStrut(offset)
				.Add(_CreateLabel("cpulabel", processorLabel))
				.Add(cpuView)
				.Add(frequencyView)
				.AddStrut(offset)
				.Add(_CreateLabel("memlabel", B_TRANSLATE("Memory:")))
				.Add(memSizeView)
				.Add(fMemView)
				.AddStrut(offset)
				.Add(_CreateLabel("kernellabel", B_TRANSLATE("Kernel:")))
				.Add(kernelView)
				.AddStrut(offset)
				.Add(_CreateLabel("uptimelabel",
					B_TRANSLATE("Time running:")))
				.Add(fUptimeView)
				.SetInsets(5, 5, 5, 5)
			.End()
			// TODO: investigate: adding this causes the time to be cut
			//.AddGlue()
		.End()
		.Add(_CreateCreditsView());

	float min = fMemView->MinSize().width * 1.1f;
	fCreditsView->SetExplicitMinSize(BSize(min, min));
}
Esempio n. 13
0
void
BApplication::_InitData(const char* signature, bool initGUI, status_t* _error)
{
	DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error));
	// check whether there exists already an application
	if (be_app)
		debugger("2 BApplication objects were created. Only one is allowed.");

	fServerLink = new BPrivate::PortLink(-1, -1);
	fServerAllocator = NULL;
	fInitialWorkspace = 0;
	//fDraggedMessage = NULL;
	fReadyToRunCalled = false;

	// initially, there is no pulse
	fPulseRunner = NULL;
	fPulseRate = 0;

	// check signature
	fInitError = check_app_signature(signature);
	fAppName = signature;

#ifndef RUN_WITHOUT_REGISTRAR
	bool isRegistrar = signature
		&& strcasecmp(signature, kRegistrarSignature) == 0;
	// get team and thread
	team_id team = Team();
	thread_id thread = BPrivate::main_thread_for(team);
#endif

	// get app executable ref
	entry_ref ref;
	if (fInitError == B_OK) {
		fInitError = BPrivate::get_app_ref(&ref);
		if (fInitError != B_OK) {
			DBG(OUT("BApplication::InitData(): Failed to get app ref: %s\n",
				strerror(fInitError)));
		}
	}

	// get the BAppFileInfo and extract the information we need
	uint32 appFlags = B_REG_DEFAULT_APP_FLAGS;
	if (fInitError == B_OK) {
		BAppFileInfo fileInfo;
		BFile file(&ref, B_READ_ONLY);
		fInitError = fileInfo.SetTo(&file);
		if (fInitError == B_OK) {
			fileInfo.GetAppFlags(&appFlags);
			char appFileSignature[B_MIME_TYPE_LENGTH];
			// compare the file signature and the supplied signature
			if (fileInfo.GetSignature(appFileSignature) == B_OK
				&& strcasecmp(appFileSignature, signature) != 0) {
				printf("Signature in rsrc doesn't match constructor arg. (%s, %s)\n",
					signature, appFileSignature);
			}
		} else {
			DBG(OUT("BApplication::InitData(): Failed to get info from: "
				"BAppFileInfo: %s\n", strerror(fInitError)));
		}
	}

#ifndef RUN_WITHOUT_REGISTRAR
	// check whether be_roster is valid
	if (fInitError == B_OK && !isRegistrar
		&& !BRoster::Private().IsMessengerValid(false)) {
		printf("FATAL: be_roster is not valid. Is the registrar running?\n");
		fInitError = B_NO_INIT;
	}

	// check whether or not we are pre-registered
	bool preRegistered = false;
	app_info appInfo;
	if (fInitError == B_OK && !isRegistrar) {
		if (BRoster::Private().IsAppRegistered(&ref, team, 0, &preRegistered,
				&appInfo) != B_OK) {
			preRegistered = false;
		}
	}
	if (preRegistered) {
		// we are pre-registered => the app info has been filled in
		// Check whether we need to replace the looper port with a port
		// created by the roster.
		if (appInfo.port >= 0 && appInfo.port != fMsgPort) {
			delete_port(fMsgPort);
			fMsgPort = appInfo.port;
		} else
			appInfo.port = fMsgPort;
		// check the signature and correct it, if necessary, also the case
		if (strcmp(appInfo.signature, fAppName))
			BRoster::Private().SetSignature(team, fAppName);
		// complete the registration
		fInitError = BRoster::Private().CompleteRegistration(team, thread,
						appInfo.port);
	} else if (fInitError == B_OK) {
		// not pre-registered -- try to register the application
		team_id otherTeam = -1;
		// the registrar must not register
		if (!isRegistrar) {
			fInitError = BRoster::Private().AddApplication(signature, &ref,
				appFlags, team, thread, fMsgPort, true, NULL, &otherTeam);
			if (fInitError != B_OK) {
				DBG(OUT("BApplication::InitData(): Failed to add app: %s\n",
					strerror(fInitError)));
			}
		}
		if (fInitError == B_ALREADY_RUNNING) {
			// An instance is already running and we asked for
			// single/exclusive launch. Send our argv to the running app.
			// Do that only, if the app is NOT B_ARGV_ONLY.
			if (otherTeam >= 0) {
				BMessenger otherApp(NULL, otherTeam);
				app_info otherAppInfo;
				bool argvOnly = be_roster->GetRunningAppInfo(otherTeam,
						&otherAppInfo) == B_OK
					&& (otherAppInfo.flags & B_ARGV_ONLY) != 0;

				if (__libc_argc > 1 && !argvOnly) {
					// create an B_ARGV_RECEIVED message
					BMessage argvMessage(B_ARGV_RECEIVED);
					fill_argv_message(argvMessage);

					// replace the first argv string with the path of the
					// other application
					BPath path;
					if (path.SetTo(&otherAppInfo.ref) == B_OK)
						argvMessage.ReplaceString("argv", 0, path.Path());

					// send the message
					otherApp.SendMessage(&argvMessage);
				} else if (!argvOnly)
					otherApp.SendMessage(B_SILENT_RELAUNCH);
			}
		} else if (fInitError == B_OK) {
			// the registrations was successful
			// Create a B_ARGV_RECEIVED message and send it to ourselves.
			// Do that even, if we are B_ARGV_ONLY.
			// TODO: When BLooper::AddMessage() is done, use that instead of
			// PostMessage().

			DBG(OUT("info: BApplication successfully registered.\n"));

			if (__libc_argc > 1) {
				BMessage argvMessage(B_ARGV_RECEIVED);
				fill_argv_message(argvMessage);
				PostMessage(&argvMessage, this);
			}
			// send a B_READY_TO_RUN message as well
			PostMessage(B_READY_TO_RUN, this);
		} else if (fInitError > B_ERRORS_END) {
			// Registrar internal errors shouldn't fall into the user's hands.
			fInitError = B_ERROR;
		}
	}
#else
	// We need to have ReadyToRun called even when we're not using the registrar
	PostMessage(B_READY_TO_RUN, this);
#endif	// ifndef RUN_WITHOUT_REGISTRAR

	if (fInitError == B_OK) {
		// TODO: Not completely sure about the order, but this should be close.

		// init be_app and be_app_messenger
		be_app = this;
		be_app_messenger = BMessenger(NULL, this);

		// set the BHandler's name
		SetName(ref.name);

		// create meta MIME
		BPath path;
		if (path.SetTo(&ref) == B_OK)
			create_app_meta_mime(path.Path(), false, true, false);

#ifndef RUN_WITHOUT_APP_SERVER
		// app server connection and IK initialization
		if (initGUI)
			fInitError = _InitGUIContext();
#endif	// RUN_WITHOUT_APP_SERVER
	}

	// Return the error or exit, if there was an error and no error variable
	// has been supplied.
	if (_error) {
		*_error = fInitError;
	} else if (fInitError != B_OK) {
		DBG(OUT("BApplication::InitData() failed: %s\n", strerror(fInitError)));
		exit(0);
	}
DBG(OUT("BApplication::InitData() done\n"));
}
Esempio n. 14
0
int
main(int argc, char *argv[])
{
	if (argc < 3) {
		if (argc < 2)
			return errorOut(e_app_sys_switch);

		return errorOut(e_specify_version);
	}

	// reset version infos

	version_info systemVersion, appVersion;
	memset(&systemVersion, 0, sizeof(version_info));
	memset(&appVersion, 0, sizeof(version_info));

	// process arguments

	processing_mode mode;
	arg_needed argNeeded;
	bool systemModified, appModified;

	parse(systemModified, appModified, argNeeded, mode, systemVersion,
		appVersion, argc, argv);

	// write back changes

	BFile file;
	status_t status = file.SetTo(argv[1], B_READ_WRITE);
	if (status != B_OK)
		errorOut(status, argv[1], false);

	BAppFileInfo info;
	status = info.SetTo(&file);
	if (status != B_OK)
		errorOut(status, argv[1], false);

	if (systemModified ^ appModified) {
		// clear out other app info if not present - this works around a
		// bug in BeOS, see bug #681.
		version_kind kind = systemModified ? B_APP_VERSION_KIND : B_SYSTEM_VERSION_KIND;
		version_info clean;

		if (info.GetVersionInfo(&clean, kind) != B_OK) {
			memset(&clean, 0, sizeof(version_info));
			info.SetVersionInfo(&clean, kind);
		}
	}

	if (appModified) {
		status = info.SetVersionInfo(&appVersion, B_APP_VERSION_KIND);
		if (status < B_OK)
			errorOut(status, NULL, false);
	}

	if (systemModified) {
		status = info.SetVersionInfo(&systemVersion, B_SYSTEM_VERSION_KIND);	
		if (status < B_OK)
			errorOut(status, NULL, false);
	}	

	return 0;
}
Esempio n. 15
0
// main
int
main(int argc, const char *const *argv)
{
	kArgc = argc;
	kArgv = argv;

	// parameters
	const char **files = new const char*[argc];
	int fileCount = 0;
	const char *type = NULL;
	const char *signature = NULL;
	const char *preferredApp = NULL;
	
	// parse the arguments
	for (int argi = 1; argi < argc; ) {
		const char *arg = argv[argi++];
		if (arg[0] == '-') {
			if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
				print_usage_and_exit(false);

			} else if (strcmp(arg, "-preferredAppSig") == 0) {
				preferredApp = next_arg(argi);

			} else if (strcmp(arg, "-s") == 0) {
				signature = next_arg(argi);

			} else if (strcmp(arg, "-t") == 0) {
				type = next_arg(argi);

			} else {
				fprintf(stderr, "Error: Invalid option: \"%s\"\n", arg);
				print_usage_and_exit(true);
			}
		} else {
			// file
			files[fileCount++] = arg;
		}
	}

	// check parameters
	if (!preferredApp && !signature && !type) {
		fprintf(stderr, "Error: At least one option of \"-preferredAppSig\", "
			"\"-s\", and \"-t\" must be given.\n");
		print_usage_and_exit(true);
	}

	if (fileCount == 0) {
		fprintf(stderr, "Error: No file specified.\n");
		print_usage_and_exit(true);
	}	

	// check for valid MIME types
	check_mime_type(preferredApp);
	check_mime_type(type);
	check_mime_type(signature);

	// iterate through the files
	for (int i = 0; i < fileCount; i++) {
		const char *fileName = files[i];

		// check, whether the file exists
		BEntry entry;
		status_t error = entry.SetTo(fileName, false);
		if (error != B_OK) {
			fprintf(stderr, "Error: Can't access file \"%s\": %s\n",
				fileName, strerror(error));

			exit(1);
		}

		if (!entry.Exists()) {
			fprintf(stderr, "Error: \"%s\": No such file or directory.\n",
				fileName);

			exit(1);
		}

		// ... and has the right type
		if (signature && !entry.IsFile()) {
			fprintf(stderr, "Error: \"%s\" is not a file. Signatures can only "
				"be set for executable files.\n", fileName);

			exit(1);
		}

		// open the file
		BFile file;
		BNode _node;
		BNode &node = (signature ? file : _node);
		error = (signature ? file.SetTo(fileName, B_READ_WRITE)
			: node.SetTo(fileName));
		if (error != B_OK) {
			fprintf(stderr, "Error: Failed to open file \"%s\": %s\n",
				fileName, strerror(error));

			exit(1);
		}

		// prepare an node/app info object
		BAppFileInfo appInfo;
		BNodeInfo _nodeInfo;
		BNodeInfo &nodeInfo = (signature ? appInfo : _nodeInfo);
		error = (signature ? appInfo.SetTo(&file) : nodeInfo.SetTo(&node));
		if (error != B_OK) {
			fprintf(stderr, "Error: Failed to open file \"%s\": %s\n",
				fileName, strerror(error));

			exit(1);
		}

		// set preferred app
		if (preferredApp) {
			error = nodeInfo.SetPreferredApp(preferredApp);
			if (error != B_OK) {
				fprintf(stderr, "Error: Failed to set the preferred "
					"application of file \"%s\": %s\n", fileName,
					strerror(error));

				exit(1);
			}
		}

		// set type
		if (type) {
			error = nodeInfo.SetType(type);
			if (error != B_OK) {
				fprintf(stderr, "Error: Failed to set the MIME type of file "
					"\"%s\": %s\n", fileName, strerror(error));

				exit(1);
			}
		}

		// set signature
		if (signature) {
			error = appInfo.SetSignature(signature);
			if (error != B_OK) {
				fprintf(stderr, "Error: Failed to set the signature of file "
					"\"%s\": %s\n", fileName, strerror(error));

				exit(1);
			}
		}
	}

	return 0;
}