Example #1
0
History::History (const char *name) : mName (name)
{
    if (name == 0)
	throw AppException (WHERE, ERR_INTERNAL);

    for (int i = 0; i < HIST_SIZE; i++)
	mpText[i] = 0;

    char subKey[256];
    strcpy (subKey, HKCU_SUBKEY_HERMIT "\\");
    strcat (subKey, mName);
    try {
	RegistryKey k (HKEY_CURRENT_USER, subKey, KEY_READ | KEY_WRITE);
	DWORD type;
	char str[3];
	for (int j = 0; j < HIST_SIZE; j++) {
	    wsprintf (str, "%d", j);
	    char *value = k.queryValue (str, type);
	    if (type == REG_SZ  &&  value != 0  &&  value[0] != '\0') {
		mpText[j] = _strdup (value);
		delete [] value;
		if (mpText[j] == 0)
		    throw AppException (WHERE, ERR_OUT_OF_MEMORY);
	    }
	    else {
		delete [] value;
		break;
	    }
	}
    }
    catch (const std::exception&) {
	// oh well, it's only the history
    }
}
Example #2
0
int Screen::writeText (const char *text)
{
    DWORD charsWritten;
    if (text == 0)
	throw AppException (WHERE, ERR_INTERNAL);
    if (WriteConsole (mScreenBuf, text, (DWORD) strlen (text), &charsWritten, 0) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "WriteConsole", GetLastError ());
    return charsWritten;
}
Example #3
0
void Screen::fillChar (int x, int y, int c, int count)
{
    DWORD charsWritten;
    if (count <= 0)
	throw AppException (WHERE, ERR_INTERNAL);
    COORD coord;
    coord.X = (SHORT) x;
    coord.Y = (SHORT) y;
    if (FillConsoleOutputCharacter (mScreenBuf, c, count, coord, &charsWritten) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "FillConsoleOutputCharacter", GetLastError ());
}
Example #4
0
void Screen::fillColors (int x, int y, WORD attr, int count)
{
    DWORD attrsWritten;
    if (count <= 0)
	throw AppException (WHERE, ERR_INTERNAL);
    COORD coord;
    coord.X = (SHORT) x;
    coord.Y = (SHORT) y;
    if (FillConsoleOutputAttribute (mScreenBuf, attr, count, coord, &attrsWritten) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "FillConsoleOutputAttribute", GetLastError ());
}
Example #5
0
int Screen::writeColors (int x, int y, const WORD *attrs, int count)
{
    DWORD attrsWritten;
    if (attrs == 0  ||  count <= 0)
	throw AppException (WHERE, ERR_INTERNAL);
    COORD c;
    c.X = (SHORT) x;
    c.Y = (SHORT) y;
    if (WriteConsoleOutputAttribute (mScreenBuf, attrs, count, c, &attrsWritten) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "WriteConsoleOutputAttribute", GetLastError ());
    return attrsWritten;
}
Example #6
0
int Screen::writeText (int x, int y, const char *text, int count)
{
    DWORD charsWritten;
    if (text == 0)
	throw AppException (WHERE, ERR_INTERNAL);
    if (count <= 0)
	count = (int) strlen (text);
    COORD c;
    c.X = (SHORT) x;
    c.Y = (SHORT) y;
    if (WriteConsoleOutputCharacter (mScreenBuf, text, count, c, &charsWritten) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "WriteConsoleOutputCharacter", GetLastError ());
    return charsWritten;
}
Example #7
0
RegistryKey::RegistryKey (HKEY hKey, const char *pSubKey, REGSAM samDesired) :
    mhKey (0)
{
    if (samDesired & KEY_CREATE_SUB_KEY) {
	DWORD disposition;
	if (RegCreateKeyEx (hKey, pSubKey, 0, 0 /*class*/, REG_OPTION_NON_VOLATILE, samDesired,
			    0, &mhKey, &disposition) != ERROR_SUCCESS)
	    throw AppException (WHERE, ERR_WINDOWS_FMT, "RegCreateKeyEx", GetLastError ());
    }
    else {
	if (RegOpenKeyEx (hKey, pSubKey, 0, samDesired, &mhKey) != ERROR_SUCCESS)
	    throw AppException (WHERE, ERR_WINDOWS_FMT, "RegOpenKeyEx", GetLastError ());
    }
}
Example #8
0
char * RegistryKey::queryValue (const char *pName, DWORD& type) const
{
    DWORD size = 0;
    if (RegQueryValueEx (mhKey, pName, 0, &type, 0, &size) != ERROR_SUCCESS)
    	throw AppException (WHERE, ERR_WINDOWS_FMT, "RegQueryValueEx", GetLastError ());
    char *data = new char [size];
    if (data == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);
    if (RegQueryValueEx (mhKey, pName, 0, &type, (BYTE*) data, &size) != ERROR_SUCCESS) {
	delete [] data;
    	throw AppException (WHERE, ERR_WINDOWS_FMT, "RegQueryValueEx", GetLastError ());
    }
    return data;
}
Example #9
0
// YOU must free the returned string
char * getSpecialFolder (int nFolder, HWND hWnd)
{
    LPMALLOC pMalloc;
    LPITEMIDLIST pidl;

    ArrayPtr<char> str = new char [MAX_PATH + 30];
    if (str == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);

    if (FAILED (SHGetMalloc (&pMalloc)))
	return NULL;

    if (FAILED (SHGetSpecialFolderLocation (hWnd, nFolder, &pidl))) {
	pMalloc->Release ();
	return NULL;
    }

    if (SHGetPathFromIDList (pidl, str) != TRUE) {
	pMalloc->Free (pidl);
	pMalloc->Release ();
	return NULL;
    }

    pMalloc->Free (pidl);
    pMalloc->Release ();

    return str.detach ();
}
Example #10
0
void History::add (const char *text)
{
    int i;

    if (text == 0  ||  *text == '\0')
	return;	    // don't add blanks to the history

    // See if the string is already in the list; if so, promote it to front
    for (i = 0; i < HIST_SIZE  &&  mpText[i] != 0; i++) {
	if (strcmp (mpText[i], text) == 0) {
	    char *p = mpText[i];
	    for (int j = i; j > 0; j--)
		mpText[j] = mpText[j - 1];
	    mpText[0] = p;
	    return;
	}
    }

    // Add the string
    if (mpText[HIST_SIZE - 1] != 0)
	free (mpText[HIST_SIZE - 1]);
    for (i = HIST_SIZE - 1; i > 0; i--)
	mpText[i] = mpText[i - 1];
    mpText[0] = _strdup (text);
    if (mpText[0] == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);
}
Example #11
0
void RegistryKey::setValue (const char *pName, const char *value)
{
    if (value == 0)
	value = "";
    if (RegSetValueEx (mhKey, pName, 0, REG_SZ, (const BYTE *)value, (DWORD) strlen (value) + 1) != ERROR_SUCCESS)
    	throw AppException (WHERE, ERR_WINDOWS_FMT, "RegSetValueEx", GetLastError ());
}
Example #12
0
void RegistryKey::reOpen (HKEY hKey, const char *pSubKey, REGSAM samDesired)
{
    RegCloseKey (mhKey);
    mhKey = 0;
    if (RegOpenKeyEx (hKey, pSubKey, 0, samDesired, &mhKey) != ERROR_SUCCESS)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "RegOpenKeyEx", GetLastError ());
}
Example #13
0
	void Player::PickItems(std::list<GameObject*>& objects)
	{
		for (std::list<GameObject*>::iterator it = objects.begin(); it != objects.end(); ++it)
		{
			Item* item = dynamic_cast<Item*>(*it);
			if ((item != nullptr) && item->IsAlive() && item->IsCollidingWith(*this))
			{
				switch (item->GetType())
				{
					case ItemType::Bomb:
						maxBombs_++;
						availableBombs_++;
						break;
					case ItemType::Power:
						power_++;
						break;
					case ItemType::Speed:
						speedBonus_ += 2;
						break;
					default:
						throw AppException("Unexpected enum value.", "Player::PickItems");
				}
				item->Kill();
			}
		}
	}
Example #14
0
RegistryKey::RegistryKey (HKEY hKey, const char *pSubKey, REGSAM samDesired, DWORD options) :
    mhKey (0)
{
    DWORD disposition;
    if (RegCreateKeyEx (hKey, pSubKey, 0, 0 /*class*/, options, samDesired,
		        0, &mhKey, &disposition) != ERROR_SUCCESS)
        throw AppException (WHERE, ERR_WINDOWS_FMT, "RegCreateKeyEx", GetLastError ());
}
Example #15
0
void RegistryKey::CLSIDtochar (const CLSID& clsid, char *pCLSID, int length)
{
    if (length < CLSID_STRING_SIZE)
	throw AppException (WHERE, ERR_INTERNAL);

    // Get CLSID
    LPOLESTR wszCLSID = NULL ;
    HRESULT hr = StringFromCLSID(clsid, &wszCLSID) ;
    if (FAILED (hr))
	throw AppException (WHERE, ERR_WINDOWS_FMT, "StringFromCLSID", GetLastError ());

    // Covert from wide characters to non-wide.
    wcstombs (pCLSID, wszCLSID, length) ;

    // Free memory.
    CoTaskMemFree (wszCLSID) ;
}
Example #16
0
CommandDialog::CommandDialog (Screen& screen) :
    Popup (screen, 57, 21)
{
    draw ();
    mpScroller = new CommandScroller (screen, mX + 2, mY + 5, 53, 14);
    if (mpScroller == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);
}
Example #17
0
/*
 * Inicializálja a BCM2835 modult és az alkalmazott GPIO-kat.
 */
void ActuatorImpl::initialize() {
    if(!bcm2835_init())
        throw AppException("BCM2835 initialization failed at Actuator module.");

    /* A GPIO 17 és a GPIO 18 beállítása kimeneteknek. */
    bcm2835_gpio_fsel(RPI_GPIO_P1_11, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(RPI_GPIO_P1_12, BCM2835_GPIO_FSEL_OUTP);
}
Example #18
0
void Screen::getSize (int& x, int& y)
{
    CONSOLE_SCREEN_BUFFER_INFO info;
    if (GetConsoleScreenBufferInfo (mScreenBuf, &info) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "GetConsoleScreenBufferInfo", GetLastError ());
    x = info.dwSize.X;
    y = info.dwSize.Y;
}
Example #19
0
void Screen::write (int x, int y, const CHAR_INFO *pBuf, int count)
{
    if (pBuf == 0  ||  count <= 0)
	throw AppException (WHERE, ERR_INTERNAL);

    COORD bufSize, bufOrigin;
    bufSize.X = (SHORT) count;
    bufSize.Y = 1;
    bufOrigin.X = bufOrigin.Y = 0;
    SMALL_RECT rect;
    rect.Left = (SHORT) x;
    rect.Top = (SHORT) y;
    rect.Right = (SHORT) (x + count - 1);
    rect.Bottom = (SHORT) y;
    if (WriteConsoleOutput (mScreenBuf, pBuf, bufSize, bufOrigin, &rect) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "WriteConsoleOutput", GetLastError ());
}
Example #20
0
void Screen::setCursorPosition (int x, int y)
{
    COORD pos;
    pos.X = (SHORT) x;
    pos.Y = (SHORT) y;
    if (SetConsoleCursorPosition (mScreenBuf, pos) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "SetConsoleCursorPosition", GetLastError ());
}
Example #21
0
GotoDialog::GotoDialog (Screen& screen, char *pText, int length, History *pHist) :
    Popup (screen, 80, 6)
{
    draw ();
    mpEdit = new Edit (screen, mX + 2, mY + 3, 76, pText, length, pHist);
    if (mpEdit == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);
}
Example #22
0
Screen::Screen () :
    mModeSwitcher (static_cast<Runable&>(*this), ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT)
{
    mScreenBuf = CreateConsoleScreenBuffer (GENERIC_READ | GENERIC_WRITE, 0, 0,
					    CONSOLE_TEXTMODE_BUFFER, 0);
    if (mScreenBuf == INVALID_HANDLE_VALUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "CreateConsoleScreenBuffer", GetLastError ());
    setCursor ();   // disable cursor
}
Example #23
0
void Edit::drawText ()
{
    int textOffset = mTextCursor - mWindowCursor;
    if (textOffset < 0)
	throw AppException (WHERE, ERR_INTERNAL);
    int n = writeText (0, 0, &mpText[textOffset], (mLength > mWidth ? mWidth : mLength));
    if (n < mWidth)
	fillChar (n, 0, ' ', mWidth - n);
}
Example #24
0
void ScrollConfig::getAttributes (int pos, WORD *attrs, int width) const
{
    if (attrs == 0)
	throw AppException (WHERE, ERR_INTERNAL);

    WORD clr = (pos == 0 ? getColor (ceVerbCursor) : getColor (ceVerb));

    for (int i = 0; i < width; i++)
	attrs[i] = clr;
}
Example #25
0
void Screen::scroll (int destX, int destY, const SMALL_RECT& scrollRect, const SMALL_RECT *pClipRect)
{
    CHAR_INFO fill;
    fill.Char.AsciiChar = ' ';
    fill.Attributes = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
    COORD dest;
    dest.X = destX;
    dest.Y = destY;
    if (ScrollConsoleScreenBuffer (mScreenBuf, &scrollRect, pClipRect, dest, &fill) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "ScrollConsoleScreenBuffer", GetLastError ());
}
Example #26
0
int Screen::ask (const char *title, const char *msg)
{
    if (title == 0  ||  msg == 0)
	throw AppException (WHERE, ERR_INTERNAL);

    AskDialog dlg (*this, title, msg);
    dlg.run ();
    if (dlg.getExitCode () == KB_ENTER)
	return 1;
    else
	return 0;
}
Example #27
0
Edit::Edit (Screen& screen, int x, int y, int w, char *text, int length, History *pHist) :
    Popup (screen, x, y, w, 1), mpRealText (text), mpHist (pHist), mMaxLength (length),
    mbInsMode (1), mWindowCursor (0), mTextCursor (0), mHistIndex (-1)
{
    if (text == 0  ||  length <= 0)
	throw AppException (WHERE, ERR_INTERNAL);

    mLength = (int) strlen (mpRealText);
    if (mLength > mMaxLength)
	throw AppException (WHERE, ERR_INTERNAL);
    mpText = new char [mMaxLength + 1];
    if (mpText == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);
    strncpy (mpText, mpRealText, mMaxLength);
    mpText[mMaxLength] = '\0';
    if (mpHist != 0  &&  mpHist->mpText[0] != 0  &&  strcmp (mpText, mpHist->mpText[0]) == 0)
	mHistIndex = 0;
    setCursor (1);	// zero disables the cursor
    setCursorPosition ();
    draw ();
}
Example #28
0
	ConnectionPtr Instance::getConnection(const string& name)
	{
		conn_map_t::iterator it = conn_map_.find(name);
		if (it != conn_map_.end())
		{
			if (!it->second->isClosed())
				return it->second;
			conn_map_.erase(it);
		}
		throw AppException("connection closed");
		return NULL;
	}
float MotionGraphController::getValue(CHANNEL_ID _channel, float _time)
{
	// update internal state (if time has passed since last external access)
	update(_time);

	MotionSequence *motion_sequence = lookupMotionSequenceByID(status.active_seqID);
	if (motion_sequence == NULL)
	{
		stringstream ss;
		ss << "MotionGraphController::getValue: MotionGraphController has no attached MotionSequence for " << status.active_seqID;
		logout << ss.str() << endl;
		throw AppException(ss.str().c_str());
	}
	if (!isValidChannel(_channel, _time))
	{
		stringstream ss;
		ss << "MotionSequenceController received request for invalid channel bone: "
			<< _channel.bone_id << " dof: " << _channel.channel_type;
		throw AppException(ss.str().c_str());
	}
	return motion_sequence->getValue(_channel, status.active_frame);
}
Example #30
0
void RegistryKey::privateRemove (HKEY hKey, const char *pSubKey)
{
    // Open the child.
    HKEY hKeyChild ;
    LONG lRes = RegOpenKeyEx (hKey, pSubKey, 0, KEY_ALL_ACCESS, &hKeyChild);
    if (lRes != ERROR_SUCCESS)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "RegOpenKeyEx", GetLastError ());

    // Enumerate all of the decendents of this child.
    FILETIME time;
    char szBuffer[256];
    DWORD dwSize = 256;
    LONG rval;
    while ((rval = RegEnumKeyEx (hKeyChild, 0, szBuffer, &dwSize, NULL,
	                 NULL, NULL, &time)) == ERROR_SUCCESS) {
	// Delete the decendents of this child.
	try {
	    privateRemove (hKeyChild, szBuffer);
	}
	catch (const std::exception&) {
	    // Cleanup before exiting.
	    RegCloseKey (hKeyChild);
	    throw;
	}

	dwSize = 256 ;
    }

    if (rval != ERROR_NO_MORE_ITEMS)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "RegEnumKeyEx", GetLastError ());

    // Close the child.
    RegCloseKey (hKeyChild);

    // Delete this child.
    if (RegDeleteKey (hKey, pSubKey) != ERROR_SUCCESS)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "RegDeleteKey", GetLastError ());
}