PString APServerCommunication::SendCommand(void *handle, PString command)
{
	BMessenger messenger(NULL, serverLooper);
	BMessage message(APSERVER_MSG_DATA);
	BMessage reply;
	const char *replyCmd;
	char *cmdStr;

	// Just add the looper and command to the message
	message.AddPointer("ClientLooper", handle);
	message.AddString("Command", (cmdStr = command.GetString()));
	command.FreeBuffer(cmdStr);

	// Send the command and wait for the reply
	messenger.SendMessage(&message, &reply);

	if (reply.what != APSERVER_MSG_OK)
	{
		// The server couldn't understand or run the command
		//
		// Find the error string
		if (reply.FindString("Result", &replyCmd) == B_OK)
			return (PString("ERR=") + replyCmd);

		return ("ERR=0");
	}

	// Extract the answer from the reply message
	if (reply.FindString("Result", &replyCmd) != B_OK)
		return ("");

	return (replyCmd);
}
void RIFFWAVESettingsWindow::GetSettings(void)
{
	PString tempStr;
	char *tempPoi;
	BMenuItem *item;

	// Set the output format
	tempStr = useSettings->GetStringEntryValue("General", "OutputFormat");
	tempPoi = tempStr.GetString();
	item    = formatPop->FindItem(tempPoi);
	if (item != NULL)
		item->SetMarked(true);

	tempStr.FreeBuffer(tempPoi);
}
Example #3
0
bool APModuleLoader::LoadModule(PString fileName, bool changeType, PString &errorStr)
{
	APAgent_DecrunchFile decrunchInfo;
	APAgent_ConvertModule convInfo;
	APMRSWList<AddOnInfo *> *infoList;
	bool modConverted = false;
	bool foundType = false;
	bool result = false;
	ap_result apResult;

	// Allocate the file object
	file = new PCacheFile();
	if (file == NULL)
		throw PMemoryException();

	try
	{
		// Initialize the converter structure
		convInfo.moduleFile         = NULL;
		convInfo.newModuleFile      = NULL;

		// Initialize the decruncher structure
		decrunchInfo.file           = file;
		decrunchInfo.decrunchedFile = NULL;

		// Open the module
		decrunchInfo.file->Open(fileName, PFile::pModeReadWrite | PFile::pModeShareRead | PFile::pModeNoTruncate);

		// Get the original length of the file
		fileLength = decrunchInfo.file->GetLength();

		// Decrunch the file
		DecrunchFile(&decrunchInfo);

		// Copy the file used for decrunching into the converter structure
		convInfo.moduleFile = decrunchInfo.file;

		// Well, lock the player list
		infoList = &GetApp()->playerInfo;
		infoList->WaitToRead();

		try
		{
			// Check to see if we can find a player via
			// the file type
			if (!FindPlayerViaFileType(convInfo.moduleFile))
			{
				// No player could be found via the file type.
				// Now try to convert the module
				modConverted = ConvertModule(&convInfo);

				// Try all the players to see if we can find
				// one that understand the file format
				if (FindPlayer(convInfo.moduleFile))
					result = true;
			}
			else
			{
				foundType = true;
				result    = true;
			}

			// Did we found a player?
			if (result)
			{
				PString typeString;
				PString playerError;

				// Yap, change the file type
				if (changeType && !foundType)
				{
					try
					{
						// Change the module type on the file
						if (modConverted)
						{
							if (convInfo.fileType.IsEmpty())
								typeString = player->GetModTypeString(playerInfo->index);
							else
								typeString = convInfo.fileType;
						}
						else
							typeString = player->GetModTypeString(playerInfo->index);

						if (!typeString.IsEmpty())
							file->SetFileType(typeString);
					}
					catch(PFileException e)
					{
						// If we can't set the file type, we ignore the error.
						// An error will occure on e.g. CD-ROM disks
						;
					}
				}

				// Yap, load the module
				convInfo.moduleFile->SeekToBegin();
				apResult = player->LoadModule(playerInfo->index, convInfo.moduleFile, playerError);

				if (apResult != AP_OK)
				{
					// Well, something went wrong when loading the file
					//
					// Build the error string
					errorStr.Format_S3(GetApp()->resource, IDS_CMDERR_LOAD_MODULE, fileName, playerInfo->addOnName, playerError);

					// Delete the player
					playerInfo->loader->DeleteInstance(player);
					player     = NULL;
					playerInfo = NULL;

					result = false;
				}
				else
				{
					// Get module information
					playerName = playerInfo->addOnName;

					if (modConverted)
					{
						moduleFormat = convInfo.modKind;
						if (moduleFormat.IsEmpty())
							moduleFormat = playerInfo->addOnName;
					}
					else
						moduleFormat = playerInfo->addOnName;

					// Should the file still be open?
					if (player->GetSupportFlags(playerInfo->index) & appDontCloseFile)
					{
						// Yes, remember the file pointer
						if (modConverted)
						{
							usingFile = convInfo.newModuleFile;
							convInfo.newModuleFile = NULL;
						}
						else
						{
							usingFile = file;
							file      = NULL;
						}
					}
				}
			}
			else
			{
				// Nup, send an error back
				errorStr.Format_S1(GetApp()->resource, IDS_CMDERR_UNKNOWN_MODULE, fileName);
			}
		}
		catch(...)
		{
			infoList->DoneReading();
			throw;
		}

		// Done with the list
		infoList->DoneReading();
	}
	catch(PFileException e)
	{
		PString err;
		char *fileStr, *errStr;

		// Build error message
		err = PSystem::GetErrorString(e.errorNum);
		errorStr.Format(GetApp()->resource, IDS_CMDERR_FILE, (fileStr = fileName.GetString()), e.errorNum, (errStr = err.GetString()));
		err.FreeBuffer(errStr);
		fileName.FreeBuffer(fileStr);
		result = false;
	}
	catch(...)
	{
		;
	}

	// Close the files again
	delete convInfo.newModuleFile;
	delete file;
	file = NULL;

	return (result);
}
RIFFWAVESettingsWindow::RIFFWAVESettingsWindow(PResource *resource, PString title) : BWindow(BRect(0.0f, 0.0f, 0.0f, 0.0f), NULL, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
{
	BRect rect;
	PString label;
	char *labelPtr, *titlePtr;
	float titWidth, winWidth;
	float controlWidth, controlHeight;
	float w, w1, x, y;
	BMessage *message;
	font_height fh;
	float fontHeight;

	// Remember the config information
	res = resource;

	// Set the window title
	SetTitle((titlePtr = title.GetString()));

	// Create background view
	rect    = Bounds();
	topView = new BView(rect, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW);

	// Change the color to light grey
	topView->SetViewColor(BeBackgroundGrey);

	// Add view to the window
	AddChild(topView);

	// Find font height
	topView->GetFontHeight(&fh);
	fontHeight = max(PLAIN_FONT_HEIGHT, ceil(fh.ascent + fh.descent));

	// Create the listbox with the different formats
	formatPop = new BPopUpMenu("");

	label.LoadString(res, IDS_RIFFWAVE_FORMAT_MSADPCM);
	labelPtr = label.GetString();
	w = topView->StringWidth(labelPtr);
	formatPop->AddItem(new BMenuItem(labelPtr, NULL));
	label.FreeBuffer(labelPtr);

	label.LoadString(res, IDS_RIFFWAVE_FORMAT_PCM);
	labelPtr = label.GetString();
	w = max(topView->StringWidth(labelPtr), w);
	formatPop->AddItem(new BMenuItem(labelPtr, NULL));
	label.FreeBuffer(labelPtr);

	label.LoadString(res, IDS_RIFFWAVE_FORMAT);
	labelPtr = label.GetString();
	w1 = topView->StringWidth(labelPtr) + HSPACE;

	formatField = new BMenuField(BRect(HSPACE, VSPACE, HSPACE + w + w1 + HSPACE * 8.0f, VSPACE + 1.0f), NULL, labelPtr, formatPop);
	formatField->SetDivider(w1);
	topView->AddChild(formatField);
	label.FreeBuffer(labelPtr);

	// Find the width of the window
	titWidth = topView->StringWidth(titlePtr);
	winWidth = max(titWidth + HSPACE * 20.0f, w + w1 + HSPACE * 8.0f);
	title.FreeBuffer(titlePtr);

	// Add the "save" button
	y = fontHeight + VSPACE * 5.0f;
	x = winWidth - HSPACE;
	message = new BMessage(APCFG_SAVE);
	label.LoadString(res, IDS_RIFFWAVE_SAVE);
	saveButton = new BButton(BRect(x, y, x, y), NULL, (labelPtr = label.GetString()), message, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
	label.FreeBuffer(labelPtr);
	saveButton->GetPreferredSize(&controlWidth, &controlHeight);
	x -= controlWidth;
	ResizeTo(winWidth, y + controlHeight + VSPACE);

	saveButton->MoveTo(x, y);
	saveButton->ResizeTo(controlWidth, controlHeight);
	topView->AddChild(saveButton);

	// Add the "Use" button
	message = new BMessage(APCFG_USE);
	label.LoadString(res, IDS_RIFFWAVE_USE);
	useButton = new BButton(BRect(x, y, x, y), NULL, (labelPtr = label.GetString()), message, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
	label.FreeBuffer(labelPtr);
	useButton->GetPreferredSize(&controlWidth, &controlHeight);
	x -= (controlWidth + HSPACE);
	useButton->MoveTo(x, y);
	useButton->ResizeTo(controlWidth, controlHeight);
	topView->AddChild(useButton);

	// Set the settings in the controls
	GetSettings();

	// Does any window position exists in the settings
	if (useSettings->EntryExist("Window", "WinX") && useSettings->EntryExist("Window", "WinY"))
	{
		// Yes, now set the new window positions
		x = useSettings->GetIntEntryValue("Window", "WinX");
		y = useSettings->GetIntEntryValue("Window", "WinY");
		MoveTo(x, y);
	}
}