Exemple #1
0
carray<char> RegReadString(char const *sect, const char *what, const char*def)
{
	HKEY hsect = GetSection(sect);
	if (!hsect) return def ? new_char_str(def) : carray<char>(0);

	carray<char> strValue;
	DWORD dwType, dwCount;
	LONG lResult = RegQueryValueEx(hsect, (LPTSTR)what, NULL, &dwType,
		NULL, &dwCount);

	if (lResult == ERROR_SUCCESS)
	{
		ASSERT(dwType == REG_SZ);
		strValue.alloc(dwCount+1);
		strValue[dwCount] = 0;

		lResult = RegQueryValueEx(hsect, (LPTSTR)what, NULL, &dwType,
			(LPBYTE)strValue.ptr(), &dwCount);
	}

	RegCloseKey(hsect);

	if (lResult == ERROR_SUCCESS)
	{
		ASSERT(dwType == REG_SZ);
		return strValue;
	}

	return def ? new_char_str(def) : carray<char>(0);
}
cfont::cfont(const char *uriStr)
: external(false)
{
	if (uriStr && *uriStr == '-') //win32 font
	{
		LOGFONT lf;
		UriToLogFont(&lf, uriStr);
		handle = CreateFontIndirect(&lf);
	}
	//...
	_uri = new_char_str(uriStr);
	_name = new_char_str(uriStr);
}
Exemple #3
0
void WcmConfig::Save( NCWin* nc )
{
	if ( nc )
	{
		leftPanelPath = new_char_str( nc->GetLeftPanel()->GetPath().GetUtf8() );
		rightPanelPath = new_char_str( nc->GetRightPanel()->GetPath().GetUtf8() );
		crect Rect = nc->ScreenRect();
		windowX = Rect.top;
		windowY = Rect.left;
		windowWidth = Rect.Width();
		windowHeight = Rect.Height();
	}
	
#ifdef _WIN32
	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			RegWriteInt(node.section, node.name, *node.ptr.pBool);
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			RegWriteInt(node.section, node.name, *node.ptr.pInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
			RegWriteString(node.section, node.name, node.ptr.pStr->ptr());
	}
#else 
	IniHash hash;
	FSPath path = configDirPath;
	path.Push(CS_UTF8, "config");
	hash.Load((sys_char_t*)path.GetString(sys_charset_id));

	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			hash.SetBoolValue(node.section, node.name, *node.ptr.pBool);
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			hash.SetIntValue(node.section, node.name, *node.ptr.pInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
			hash.SetStrValue(node.section, node.name, node.ptr.pStr->ptr());
	}
	
	hash.Save((sys_char_t*)path.GetString(sys_charset_id));
#endif
}
Exemple #4
0
bool DoSystemConfigDialog(NCDialogParent *parent)
{
	SysOptDialog dlg(parent);

	if (dlg.DoModal() == CMD_OK)
	{
		wcmConfig.systemAskOpenExec = dlg.askOpenExecButton.IsSet(); 
		wcmConfig.systemEscPanel = dlg.escPanelButton.IsSet();
		wcmConfig.systemBackSpaceUpDir = dlg.backUpDirButton.IsSet();
		const char *s = wcmConfig.systemLang.ptr();
		if (!s) s = "+";
		bool langChanged = strcmp(dlg.curLangId.ptr(), s) != 0;
		wcmConfig.systemLang = new_char_str(dlg.curLangId.ptr());
		
		if (langChanged) 
		{
			NCMessageBox(parent, _LT("Note"), 
				_LT("Language changed. \nFor effect you must save config and restart"), false);
		}
		
		return true;
	}

	return false;
}
Exemple #5
0
void SaveOperCharsets()
{
	ccollect< carray<char> > stringList;
	for (int i = 0; i<csList.count(); i++)
		stringList.append(new_char_str(csList[i]->name));
	SaveStringList(charsetSection, stringList);
}
Exemple #6
0
void IniHash::Load(const sys_char_t *fileName)
{
//	Clear();
	SysTextFileIn in;
	try {
		in.Open(fileName);
	} catch (csyserr *ex) {
		if (SysErrorIsFileNotFound(ex->code))
		{
			ex->destroy();
			return;
		}
		throw;
	}
	
	char buf[4096];
	carray<char> section;
		
	while (in.GetLine(buf, sizeof(buf)))
	{

		char *s = buf;
		while (IsSpace(*s)) s++;
		if (!*s || *s == '#') continue;
		if (*s == '[')
		{
			s++;
			while (IsSpace(*s)) s++;
			char *t = s;
			while (*t && *t != ']') t++;
			if (*t != ']') continue;
			
			while ( t>s && IsSpace(*(t-1))) t--;
			*t = 0;
		
			section = new_char_str(s);
			
		} else {
			if (!section.ptr()) continue;

			char *t = s;
			while (*t && *t != '=') t++;
			if (*t != '=') continue;

			char *v = t + 1;
			while ( t>s && IsSpace(*(t-1))) t--;
			*t = 0;
			
			while (IsSpace(*v)) v++;
			t = v;
			while (*t) t++;
			while ( t>v && IsSpace(*(t-1))) t--;
			*t = 0;

			SetStrValue(section.ptr(), s, v);
		}
	}
	in.Close();
}
void KbIntCallback(
   const char* name, int name_len,
   const char* instruction, int instruction_len,
   int num_prompts,
   const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts,
   LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses,
   void** anstract )
{
	if ( num_prompts <= 0 ) { return; }

	if ( !kbdIntInfo ) { return; }

	try
	{

		std::vector<FSPromptData> pData( num_prompts );
		int i;

		for ( i = 0; i < num_prompts; i++ )
		{
			pData[i].visible = prompts[i].echo != 0;
			pData[i].prompt = utf8_to_unicode( CopyToStrZ( prompts[i].text, prompts[i].length ).data() ).data();
		}

		static unicode_t userSymbol = '@';

		if ( !kbdIntInfo->Prompt(
		        utf8_to_unicode( "SFTP" ).data(),
		        carray_cat<unicode_t>( kbdIntParam->user.Data(), &userSymbol, kbdIntParam->server.Data() ).data(),
		        pData.data(), num_prompts ) ) { return; }

		for ( i = 0; i < num_prompts; i++ )
		{
			std::vector<char> str = new_char_str( ( char* )FSString( pData[i].prompt.Data() ).Get( kbdIntParam->charset ) );

			if ( str.data() )
			{
				int l = strlen( str.data() );
				responses[i].length = l;
				responses[i].text = ( char* ) malloc( l + 1 );

				if ( responses[i].text ) { strcpy( responses[i].text, str.data() ); }

			}
		}

	}
	catch ( cexception* ex )
	{
		fprintf( stderr, "exception in kbdint callback used with libssh2: %s\n", ex->message() );
		ex->destroy();
	}
	catch ( ... )
	{
		fprintf( stderr, "excention (...) in kbdint callback used with libssh2\n" );
	}
}
Exemple #8
0
void WcmConfig::ImpCurrentFonts()
{
	panelFontUri = new_char_str(panelFont.ptr() ? panelFont->uri() : "");
	viewerFontUri = new_char_str(viewerFont.ptr() ? viewerFont->uri() : "");
	editorFontUri = new_char_str(editorFont.ptr() ? editorFont->uri() : "");
	dialogFontUri  = new_char_str(dialogFont.ptr() ? dialogFont->uri() : "");
	terminalFontUri  = new_char_str(terminalFont.ptr() ? terminalFont->uri() : "");
	helpTextFontUri  = new_char_str(helpTextFont.ptr() ? helpTextFont->uri() : "");
	helpBoldFontUri  = new_char_str(helpBoldFont.ptr() ? helpBoldFont->uri() : "");
	helpHeadFontUri  = new_char_str(helpHeadFont.ptr() ? helpHeadFont->uri() : "");
}
Exemple #9
0
bool DoStyleConfigDialog(NCDialogParent *parent)
{
	wcmConfig.ImpCurrentFonts();
	ccollect<StyleOptDialog::Node> list;
	list.append(StyleOptDialog::Node(  _LT("Panel") ,	false,	panelFont.ptr(), &wcmConfig.panelFontUri));
	list.append(StyleOptDialog::Node(  _LT("Dialog"),	false,	dialogFont.ptr(), &wcmConfig.dialogFontUri));
	list.append(StyleOptDialog::Node(  _LT("Viewer"),	true, 	viewerFont.ptr(), &wcmConfig.viewerFontUri));
	list.append(StyleOptDialog::Node(  _LT("Editor"),	true, 	editorFont.ptr(), &wcmConfig.editorFontUri));
	list.append(StyleOptDialog::Node(  _LT("Terminal"),	true,	terminalFont.ptr(), &wcmConfig.terminalFontUri));
	list.append(StyleOptDialog::Node(  _LT("Help text"),	false,	helpTextFont.ptr(), &wcmConfig.helpTextFontUri));
	list.append(StyleOptDialog::Node(  _LT("Help bold text"),	false,	helpBoldFont.ptr(), &wcmConfig.helpBoldFontUri));
	list.append(StyleOptDialog::Node(  _LT("Help header text"),	false,	helpHeadFont.ptr(), &wcmConfig.helpHeadFontUri));
	
	StyleOptDialog dlg(parent, &list);

	if (dlg.DoModal() == CMD_OK)
	{
		if (dlg.styleBlackButton.IsSet()) {
			wcmConfig.viewColorMode = wcmConfig.editColorMode = wcmConfig.panelColorMode = 1;
//			wcmConfig.whiteStyle = false;
		} else 
		if (dlg.styleWhiteButton.IsSet()) {
			wcmConfig.viewColorMode = wcmConfig.editColorMode = wcmConfig.panelColorMode = 2;
//			wcmConfig.whiteStyle = true;
		} else {
			wcmConfig.viewColorMode = wcmConfig.editColorMode = wcmConfig.panelColorMode = 0;
//			wcmConfig.whiteStyle = false;
		}

		SetColorStyle(wcmConfig.panelColorMode);
//		SetEditorColorStyle(wcmConfig.editColorMode);
//		SetViewerColorStyle(wcmConfig.viewColorMode);

		wcmConfig.showToolBar = dlg.showToolbarButton.IsSet();
		wcmConfig.showButtonBar = dlg.showButtonbarButton.IsSet();
		
		for (int i = 0; i<list.count(); i++)
			if (list[i].newFont.ptr() && list[i].newFont->uri()[0] && list[i].pUri)
			{
				*(list[i].pUri) = new_char_str(list[i].newFont->uri());
			}
		
		return true;
	}

	return false;
}
Exemple #10
0
void WcmConfig::Load()
{
#ifdef _WIN32
	
	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			*node.ptr.pBool = RegReadInt(node.section, node.name, node.def.defBool)!=0;
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			*node.ptr.pInt = RegReadInt(node.section, node.name, node.def.defInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
			*node.ptr.pStr = RegReadString(node.section, node.name, node.def.defStr);
	}

#else 
	IniHash hash;
	FSPath path = configDirPath;
	path.Push(CS_UTF8, "config");
	
	hash.Load(DEFAULT_CONFIG_PATH);
	hash.Load((sys_char_t*)path.GetString(sys_charset_id));

	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			*node.ptr.pBool = hash.GetBoolValue(node.section, node.name, node.def.defBool);
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			*node.ptr.pInt = hash.GetIntValue(node.section, node.name, node.def.defInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
		{
			const char *s = hash.GetStrValue(node.section, node.name, node.def.defStr);
			if (s) *node.ptr.pStr = new_char_str(s);
			else (*node.ptr.pStr) = 0;
		}

	}
#endif
	if (editTabSize<=0 || editTabSize >64) editTabSize = 8;
}
Exemple #11
0
void SysOptDialog::SetCurLang(const char *id)
{
	curLangId = new_char_str(id);
	if (id[0] == '-')
		langVal.SetText( utf8_to_unicode( _LT("English") ).ptr() );
	else if (id[0]=='+') 
		langVal.SetText( utf8_to_unicode( _LT("Autodetect") ).ptr() );
	else {
		for (int i = 0; i<list.count(); i++)
		{
			if (!strcmp(list[i].id.ptr(), id)) {
				langVal.SetText( utf8_to_unicode( list[i].name.ptr() ).ptr() );
				return;
			}
		}
		langVal.SetText( utf8_to_unicode( id ).ptr() );
	}
}
Exemple #12
0
bool LoadStringList(const char *section, ccollect< carray<char> > &list)
{
	try {
		SysTextFileIn in;
				
		FSPath path = configDirPath;
		path.Push(CS_UTF8, carray_cat<char>(section, ".cfg").ptr());
		in.Open( (sys_char_t*)path.GetString(sys_charset_id) );
		
		char buf[4096];
		while (in.GetLine(buf, sizeof(buf))) 
		{
			char *s = buf;
			while (*s>0 && *s<=' ') s++;
			if (*s) list.append(new_char_str(s));
		}
	} catch (cexception *ex) {
		ex->destroy();
		return false;
	}
	return true;
}
Exemple #13
0
		Node(const char *n, bool fix,  cfont *old, carray<char> *uri):name(new_char_str(n)), fixed(fix), oldFont(old), pUri(uri){}
Exemple #14
0
WcmConfig::WcmConfig()
:	systemAskOpenExec(true),
	systemEscPanel(true),
	systemBackSpaceUpDir(false),
	systemLang(new_char_str("+")),
	showToolBar(true),
	showButtonBar(true),
	//whiteStyle(false),

	panelShowHiddenFiles(true),
	panelShowIcons(true),
	panelCaseSensitive(false),
	panelColorMode(0),
	
	panelModeLeft(0),
	panelModeRight(0),
		
	editSavePos(true),
	editAutoIdent(false),
	editTabSize(3),
	editColorMode(0),
	editShl(true),
	
	terminalBackspaceKey(0),

	viewColorMode(0)
{
	leftPanelPath = new_char_str("");
	rightPanelPath = new_char_str("");

#ifndef _WIN32
	MapBool(sectionSystem, "ask_open_exec", &systemAskOpenExec, systemAskOpenExec);
#endif
	MapBool(sectionSystem, "esc_panel", &systemEscPanel, systemEscPanel);
	MapBool(sectionSystem, "back_updir", &systemBackSpaceUpDir, systemBackSpaceUpDir);
	MapStr(sectionSystem,  "lang", &systemLang);
	
	MapBool(sectionSystem, "show_toolbar", &showToolBar, showToolBar);
	MapBool(sectionSystem, "show_buttonbar", &showButtonBar, showButtonBar);
	//MapBool(sectionSystem, "white", &whiteStyle, whiteStyle);

	MapBool(sectionPanel, "show_hidden_files",	&panelShowHiddenFiles, panelShowHiddenFiles);
	MapBool(sectionPanel, "show_icons",		&panelShowIcons, panelShowIcons);
	MapBool(sectionPanel, "case_sensitive_sort",	&panelCaseSensitive, panelCaseSensitive);
	MapInt(sectionPanel,  "color_mode",		&panelColorMode, panelColorMode);
	MapInt(sectionPanel,  "mode_left",		&panelModeLeft, panelModeLeft);
	MapInt(sectionPanel,  "mode_right",		&panelModeRight, panelModeRight);

#ifdef _WIN32
	const char* defPanelPath="C:\\";
#else
	const char* defPanelPath="/";
#endif

	MapStr(sectionPanel,  "left_panel_path",&leftPanelPath,defPanelPath);
	MapStr(sectionPanel,  "right_panel_path",&rightPanelPath,defPanelPath);

	MapBool(sectionEditor, "save_file_position",		&editSavePos, editSavePos);
	MapBool(sectionEditor, "auto_ident",	&editAutoIdent, editAutoIdent);
	MapInt(sectionEditor,  "color_mode",	&editColorMode, editColorMode);
	MapInt(sectionEditor, "tab_size",	&editTabSize, editTabSize);
	MapBool(sectionEditor, "highlighting",	&editShl, editShl);
	
	MapInt(sectionTerminal, "backspace_key",	&terminalBackspaceKey, terminalBackspaceKey);
	
	MapStr(sectionFonts, "panel_font",	&panelFontUri);
	MapStr(sectionFonts, "viewer_font",	&viewerFontUri);
	MapStr(sectionFonts, "editor_font",	&editorFontUri);
	MapStr(sectionFonts, "dialog_font",	&dialogFontUri);
	MapStr(sectionFonts, "terminal_font",	&terminalFontUri);
	MapStr(sectionFonts, "helptext_font",	&helpTextFontUri);
	MapStr(sectionFonts, "helpbold_font",	&helpBoldFontUri);
	MapStr(sectionFonts, "helphead_font",	&helpHeadFontUri);

	MapInt(sectionViewer,  "color_mode",	&viewColorMode, viewColorMode);
	
	MapInt(sectionSystem,  "windowX",      &windowX,      windowX);
	MapInt(sectionSystem,  "windowY",      &windowY,      windowY);
	MapInt(sectionSystem,  "windowWidth",  &windowWidth,  windowWidth);
	MapInt(sectionSystem,  "windowHeight", &windowHeight, windowHeight);
}
Exemple #15
0
void IniHash::SetStrValue(const char *section, const char *var, const char *value){ if (!value) { Delete(section, var); return;}; carray<char>* p = Create(section, var); if (p) *p = new_char_str(value); }
Exemple #16
0
	LangListNode(const char *i, const char *n):id(new_char_str(i)), name(new_char_str(n)){}