コード例 #1
0
ファイル: edit.cpp プロジェクト: ancientlore/hermit
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
    }
}
コード例 #2
0
ファイル: cfgscr.cpp プロジェクト: ancientlore/hermit
void ConfigScroller::exportReg ()
{
    int exitCode = KB_ESC;
    char path[512];
    *path = 0;
    {
	InputDialog dlg (myScreen, "Export Custom Commands", "Enter the pathname:",
			 path, 511, &mRegHist);
	dlg.run ();
	exitCode = dlg.getExitCode ();
    }
    if (exitCode != KB_ESC) {

	if (_access (path, 0) == 0)
	    if (myScreen.ask ("Confirm File Replace", "Overwrite the existing file?") == 0)
		return;

	FILE *file = fopen (path, "w");
	if (file == NULL) {
	    myScreen.sendEvent (Event(EV_STATUS_MSG, (DWORD) "Could not create file."));
	    return;
	}

	for (int i = 0; i < 2; i++) {
	    int st, fn;
	    if (i == 0) {
		st = 'A';
		fn = 'Z';
	    }
	    else if (i == 1) {
		st = '0';
		fn = '9';
	    }

	    for (char c = st; c <= fn; c++) {
		try {
		    // Open registry key
		    RegistryKey k (HKEY_CURRENT_USER, HKCU_SUBKEY_HERMIT "\\Commands", KEY_READ);

		    char valname[2];
		    valname[0] = c;
		    valname[1] = '\0';
		    // try to read the current value
		    char *value = 0;
		    DWORD type;
		    try {
			value = k.queryValue (valname, type);
			if (type == REG_SZ  &&  value != 0  &&  value[0] != '\0') {
			    fprintf (file, "%c,%s\n", c, value);
			}
			delete [] value;
		    }
		    catch (const std::exception&) {
		    }
		}
		catch (const std::exception&) {
		}
	    }
	}
	fclose (file);
	myScreen.sendEvent (Event(EV_STATUS_MSG, (DWORD) "Commands exported."));
    }
}