コード例 #1
0
ファイル: dlg_routerres.c プロジェクト: madnessw/thesnow
void add_router_to_favorites(HWND hDlg,char *router,char favtype)
{	if(hDlgRouterRestrictions)
	{	char *favtmp2,*favtmp3;
		int favtmpsize;
		int i;
		favtmpsize=SendDlgItemMessage(hDlgRouterRestrictions,15101,WM_GETTEXTLENGTH,0,0);
		favtmp2=tor_malloc(favtmpsize+256+5);favtmp3=favtmp2;
		GetDlgItemText(hDlgRouterRestrictions,15101,favtmp2,favtmpsize+1);favtmp2+=favtmpsize;
		if((favtmpsize>2)&&((*(favtmp2-1)!=0x0d)&&(*(favtmp2-1)!=0x0a)))
		{	*favtmp2++=0x0d;*favtmp2++=0x0a;}
		*favtmp2++='[';*favtmp2++=favtype;*favtmp2++=']';*favtmp2++=32;
		for(i=0;router[i];i++)	*favtmp2++=router[i];
		*favtmp2++=13;*favtmp2++=10;*favtmp2++=0;
		tor_snprintf(favtmp2,100,get_lang_str(LANG_MB_FAV_ADDED),favtmp3+favtmpsize);
		LangMessageBox(hDlg,favtmp2,LANG_MB_FAVORITES,MB_OK);
		log(LOG_NOTICE,LD_APP,favtmp2);
		SetDlgItemText(hDlgRouterRestrictions,15101,favtmp3);
		refreshFavoriteNodes();
		tor_free(favtmp3);
	}
	else if(favtype=='X')
	{	char *tmp1=routerset_to_string(tmpOptions->ExitNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i),*tmp3=tor_malloc(256);
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->ExitNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"ExitNodes");
		tmpOptions->ExitNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp3,256,"[X] %s",router);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_FAV_ADDED),tmp3);
		LangMessageBox(hDlg,tmp2,LANG_MB_FAVORITES,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);tor_free(tmp3);
	}
	else if(favtype=='E')
	{	char *tmp1=routerset_to_string(tmpOptions->EntryNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i),*tmp3=tor_malloc(256);
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->EntryNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"EntryNodes");
		tmpOptions->EntryNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp3,256,"[E] %s",router);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_FAV_ADDED),tmp3);
		LangMessageBox(hDlg,tmp2,LANG_MB_FAVORITES,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);tor_free(tmp3);
	}
}
コード例 #2
0
/**
 * @brief Install new filter.
 * This function is called when user selects "Install" button from GUI.
 * Function allows easy installation of new filters for user. For example
 * when user has downloaded filter file from net. First we ask user to
 * select filter to install. Then we copy selected filter to private
 * filters folder.
 */
void FileFiltersDlg::OnBnClickedFilterfileInstall()
{
    CString s;
    String path;
    String userPath = theApp.m_globalFileFilter.GetUserFilterPathWithCreate();

    if (SelectFile(GetSafeHwnd(), s, path.c_str(), IDS_FILEFILTER_INSTALL, IDS_FILEFILTER_FILEMASK,
                   TRUE))
    {
        String sfile, sext;
        SplitFilename(s, NULL, &sfile, &sext);
        String filename = sfile;
        filename += _T(".");
        filename += sext;
        userPath = paths_ConcatPath(userPath, filename);
        if (!CopyFile(s, userPath.c_str(), TRUE))
        {
            // If file already exists, ask from user
            // If user wants to, overwrite existing filter
            if (paths_DoesPathExist(userPath.c_str()) == IS_EXISTING_FILE)
            {
                int res = LangMessageBox(IDS_FILEFILTER_OVERWRITE, MB_YESNO |
                                         MB_ICONWARNING);
                if (res == IDYES)
                {
                    if (!CopyFile(s, userPath.c_str(), FALSE))
                    {
                        LangMessageBox(IDS_FILEFILTER_INSTALLFAIL, MB_ICONSTOP);
                    }
                }
            }
            else
            {
                LangMessageBox(IDS_FILEFILTER_INSTALLFAIL, MB_ICONSTOP);
            }
        }
        else
        {
            FileFilterMgr *pMgr = theApp.m_globalFileFilter.GetManager();
            pMgr->AddFilter(userPath.c_str());

            // Remove all from filterslist and re-add so we can update UI
            CString selected;
            m_Filters->RemoveAll();
            theApp.m_globalFileFilter.GetFileFilters(m_Filters, selected);

            UpdateFiltersList();
        }
    }
}
コード例 #3
0
	explicit Heksedit(CWnd *pwndParent)
	{
		pv = LoadLibrary(_T("Frhed\\hekseditU.dll"));
		if (pv == nullptr)
		{
			LangMessageBox(IDS_FRHED_NOTINSTALLED, MB_OK);
			return;
		}
		wnd.Create(_T("heksedit"), nullptr, 0, CRect(), pwndParent, 1);
		get_interface()->read_ini_data();
		get_interface()->get_settings()->bSaveIni = true;
	}
コード例 #4
0
/**
 * @brief Called when user presses "New..." button.
 *
 * Asks filename for new filter from user (using standard
 * file picker dialog) and copies template file to that
 * name. Opens new filterfile for editing.
 * @todo (At least) Warn if user puts filter to outside
 * filter directories?
 * @todo Can global filter path be empty (I think not - Kimmo).
 */
void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
{
    String globalPath = theApp.m_globalFileFilter.GetGlobalFilterPathWithCreate();
    String userPath = theApp.m_globalFileFilter.GetUserFilterPathWithCreate();

    if (globalPath.empty() && userPath.empty())
    {
        LangMessageBox(IDS_FILEFILTER_NO_USERFOLDER, MB_ICONSTOP);
        return;
    }

    // Format path to template file
    String templatePath(globalPath);
    if (templatePath[templatePath.length() - 1] != '\\')
        templatePath += '\\';
    templatePath += FILE_FILTER_TEMPLATE;

    if (paths_DoesPathExist(templatePath.c_str()) != IS_EXISTING_FILE)
    {
        CString msg;
        LangFormatString2(msg, IDS_FILEFILTER_TMPL_MISSING,
                          FILE_FILTER_TEMPLATE, templatePath.c_str());
        AfxMessageBox(msg, MB_ICONERROR);
        return;
    }

    String path = globalPath.empty() ? userPath : globalPath;

    if (!globalPath.empty() && !userPath.empty())
    {
        path = CSharedFilterDlg::PromptForNewFilter(this, globalPath, userPath);
        if (path.empty()) return;
    }

    if (path.length() && path[path.length() - 1] != '\\')
        path += '\\';

    CString s;
    if (SelectFile(GetSafeHwnd(), s, path.c_str(), IDS_FILEFILTER_SAVENEW, IDS_FILEFILTER_FILEMASK,
                   FALSE))
    {
        // Fix file extension
        TCHAR file[_MAX_FNAME] = {0};
        TCHAR ext[_MAX_EXT] = {0};
        TCHAR dir[_MAX_DIR] = {0};
        TCHAR drive[_MAX_DRIVE] = {0};
        _tsplitpath(s, drive, dir, file, ext);
        if (_tcslen(ext) == 0)
        {
            s += FileFilterExt;
        }
        else if (_tcsicmp(ext, FileFilterExt) != 0)
        {
            s = drive;
            s += dir;
            s += file;
            s += FileFilterExt;
        }

        // Open-dialog asks about overwriting, so we can overwrite filter file
        // user has already allowed it.
        if (!CopyFile(templatePath.c_str(), s, FALSE))
        {
            ResMsgBox1(IDS_FILEFILTER_TMPL_COPY, templatePath.c_str(), MB_ICONERROR);
            return;
        }
        EditFileFilter(s);
        FileFilterMgr *pMgr = theApp.m_globalFileFilter.GetManager();
        int retval = pMgr->AddFilter(s);
        if (retval == FILTER_OK)
        {
            // Remove all from filterslist and re-add so we can update UI
            CString selected;
            m_Filters->RemoveAll();
            theApp.m_globalFileFilter.LoadAllFileFilters();
            theApp.m_globalFileFilter.GetFileFilters(m_Filters, selected);

            UpdateFiltersList();
        }
    }
}
コード例 #5
0
ファイル: dlg_routerres.c プロジェクト: madnessw/thesnow
void add_router_to_banlist(HWND hDlg,char *router,char bantype)
{	if(hDlgRouterRestrictions)
	{	char *bantmp2,*bantmp3;
		int bantmpsize,i;
		bantmpsize=SendDlgItemMessage(hDlgRouterRestrictions,15100,WM_GETTEXTLENGTH,0,0);
		bantmp2=tor_malloc(bantmpsize+256+5);bantmp3=bantmp2;
		GetDlgItemText(hDlgRouterRestrictions,15100,bantmp2,bantmpsize+1);bantmp2+=bantmpsize;
		if((bantmpsize>2)&&((*(bantmp2-1)!=0x0d)&&(*(bantmp2-1)!=0x0a)))
		{	*bantmp2++=0x0d;*bantmp2++=0x0a;}
		if(bantype){	*bantmp2++='[';*bantmp2++=bantype;*bantmp2++=']';*bantmp2++=32;}
		for(i=0;router[i];i++)	*bantmp2++=router[i];
		*bantmp2++=13;*bantmp2++=10;*bantmp2++=0;
		tor_snprintf(bantmp2,100,get_lang_str(LANG_MB_BAN_ADDED),bantmp3+bantmpsize);
		if(hDlg) LangMessageBox(hDlg,bantmp2,LANG_MB_BANS,MB_OK);
		log(LOG_NOTICE,LD_APP,bantmp2);
		SetDlgItemText(hDlgRouterRestrictions,15100,bantmp3);
		refreshBannedNodes();
		tor_free(bantmp3);
	}
	else if(bantype)
	{	char *tmp1=routerset_to_string(tmpOptions->ExcludeExitNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i),*tmp3=tor_malloc(256);;
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->ExcludeExitNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"ExcludeExitNodes");
		tmpOptions->ExcludeExitNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp3,256,"[X] %s",router);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_BAN_ADDED),tmp3);
		if(hDlg) LangMessageBox(hDlg,tmp2,LANG_MB_BANS,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);tor_free(tmp3);
		if(tmpOptions->ExcludeExitNodes || tmpOptions->ExcludeNodes)
		{	r2 = tmpOptions->_ExcludeExitNodesUnion;
			r1 = routerset_new();
			routerset_union(r1,tmpOptions->ExcludeExitNodes);
			routerset_union(r1,tmpOptions->ExcludeNodes);
			tmpOptions->_ExcludeExitNodesUnion = r1;
			if(r2)	routerset_free(r2);
		}
	}
	else
	{	char *tmp1=routerset_to_string(tmpOptions->ExcludeNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i);
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->ExcludeNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"ExcludeNodes");
		tmpOptions->ExcludeNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_BAN_ADDED),router);
		if(hDlg) LangMessageBox(hDlg,tmp2,LANG_MB_BANS,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);
		if(tmpOptions->ExcludeExitNodes || tmpOptions->ExcludeNodes)
		{	r2 = tmpOptions->_ExcludeExitNodesUnion;
			r1 = routerset_new();
			routerset_union(r1,tmpOptions->ExcludeExitNodes);
			routerset_union(r1,tmpOptions->ExcludeNodes);
			tmpOptions->_ExcludeExitNodesUnion = r1;
			if(r2)	routerset_free(r2);
		}
	}
}
コード例 #6
0
ファイル: PatchTool.cpp プロジェクト: sdottaka/winmerge-v2
/** 
 * @brief Create a patch from files given.
 * @note Files can be given using AddFiles() or selecting using
 * CPatchDlg.
 */
int CPatchTool::CreatePatch()
{
	DIFFSTATUS status;
	int retVal = 0;

	CPatchDlg dlgPatch;

	// If files already inserted, add them to dialog
    for(std::vector<PATCHFILES>::iterator iter = m_fileList.begin(); iter != m_fileList.end(); ++iter)
    {
        dlgPatch.AddItem(*iter);
	}

	if (ShowDialog(&dlgPatch))
	{
		bool bResult = true;

		if (!paths::CreateIfNeeded(paths::GetPathOnly(dlgPatch.m_fileResult)))
		{
			LangMessageBox(IDS_FOLDER_NOTEXIST, MB_OK | MB_ICONSTOP);
			return 0;
		}

		// Select patch create -mode
		m_diffWrapper.SetCreatePatchFile(dlgPatch.m_fileResult);
		m_diffWrapper.SetAppendFiles(dlgPatch.m_appendFile);
		m_diffWrapper.SetPrediffer(nullptr);

		size_t fileCount = dlgPatch.GetItemCount();

		m_diffWrapper.WritePatchFileHeader(dlgPatch.m_outputStyle, dlgPatch.m_appendFile);
		m_diffWrapper.SetAppendFiles(true);

		for (size_t index = 0; index < fileCount; index++)
		{
			const PATCHFILES& tFiles = dlgPatch.GetItemAt(index);
			String filename1 = tFiles.lfile.length() == 0 ? _T("NUL") : tFiles.lfile;
			String filename2 = tFiles.rfile.length() == 0 ? _T("NUL") : tFiles.rfile;
			
			// Set up DiffWrapper
			m_diffWrapper.SetPaths(PathContext(filename1, filename2), false);
			m_diffWrapper.SetAlternativePaths(PathContext(tFiles.pathLeft, tFiles.pathRight));
			m_diffWrapper.SetCompareFiles(PathContext(tFiles.lfile, tFiles.rfile));
			bool bDiffSuccess = m_diffWrapper.RunFileDiff();
			m_diffWrapper.GetDiffStatus(&status);

			if (!bDiffSuccess)
			{
				LangMessageBox(IDS_FILEERROR, MB_ICONSTOP);
				bResult = false;
				break;
			}
			else if (status.bBinaries)
			{
				LangMessageBox(IDS_CANNOT_CREATE_BINARYPATCH, MB_ICONSTOP);
				bResult = false;
				break;
			}
			else if (status.bPatchFileFailed)
			{
				String errMsg = strutils::format_string1(_("Could not write to file %1."), dlgPatch.m_fileResult);
				AfxMessageBox(errMsg.c_str(), MB_ICONSTOP);
				bResult = false;
				break;
			}
		}
		
		m_diffWrapper.WritePatchFileTerminator(dlgPatch.m_outputStyle);

		if (bResult && fileCount > 0)
		{
			LangMessageBox(IDS_DIFF_SUCCEEDED, MB_ICONINFORMATION|MB_DONT_DISPLAY_AGAIN,
				            IDS_DIFF_SUCCEEDED);
			
			m_sPatchFile = dlgPatch.m_fileResult;
			m_bOpenToEditor = dlgPatch.m_openToEditor;
			retVal = 1;
		}
	}
	dlgPatch.ClearItems();
	if (retVal)
	{
		if (m_bOpenToEditor)
			theApp.OpenFileToExternalEditor(m_sPatchFile);
	}
	return retVal;
}
コード例 #7
0
/** 
 * @brief Called when dialog is closed with "OK".
 *
 * Checks that paths are valid and sets filters.
 */
void COpenView::OnOK() 
{
	int pathsType; // enum from PATH_EXISTENCE in paths.h
	const String filterPrefix = _("[F] ");

	UpdateData(TRUE);
	TrimPaths();

	int index;
	int nFiles = 0;
	for (index = 0; index < countof(m_strPath); index++)
	{
		if (index == 2 && m_strPath[index].empty())
			break;
		m_files.SetSize(nFiles + 1);
		m_files[nFiles] = m_strPath[index];
		m_dwFlags[nFiles] &= ~FFILEOPEN_READONLY;
		m_dwFlags[nFiles] |= m_bReadOnly[index] ? FFILEOPEN_READONLY : 0;
		nFiles++;
	}
	// If left path is a project-file, load it
	String ext;
	paths_SplitFilename(m_strPath[0], NULL, NULL, &ext);
	if (m_strPath[1].empty() && string_compare_nocase(ext, ProjectFile::PROJECTFILE_EXT) == 0)
		LoadProjectFile(m_strPath[0]);

	pathsType = GetPairComparability(m_files, IsArchiveFile);

	if (pathsType == DOES_NOT_EXIST)
	{
		LangMessageBox(IDS_ERROR_INCOMPARABLE, MB_ICONSTOP);
		return;
	}

	for (index = 0; index < nFiles; index++)
	{
		// If user has edited path by hand, expand environment variables
		bool bExpand = false;
		if (string_compare_nocase(m_strBrowsePath[index], m_files[index]) != 0)
			bExpand = true;

		if (!paths_IsURLorCLSID(m_files[index]))
		{
			m_files[index] = paths_GetLongPath(m_files[index], bExpand);
	
			// Add trailing '\' for directories if its missing
			if (paths_DoesPathExist(m_files[index]) == IS_EXISTING_DIR)
				m_files[index] = paths_AddTrailingSlash(m_files[index]);
			m_strPath[index] = m_files[index];
		}
	}

	UpdateData(FALSE);
	KillTimer(IDT_CHECKFILES);

	String filter(string_trim_ws(m_strExt));

	// If prefix found from start..
	if (filter.find(filterPrefix, 0) == 0)
	{
		// Remove prefix + space
		filter.erase(0, filterPrefix.length());
		if (!theApp.m_pGlobalFileFilter->SetFilter(filter))
		{
			// If filtername is not found use default *.* mask
			theApp.m_pGlobalFileFilter->SetFilter(_T("*.*"));
			filter = _T("*.*");
		}
		GetOptionsMgr()->SaveOption(OPT_FILEFILTER_CURRENT, filter);
	}
	else
	{
		BOOL bFilterSet = theApp.m_pGlobalFileFilter->SetFilter(filter);
		if (!bFilterSet)
			m_strExt = theApp.m_pGlobalFileFilter->GetFilterNameOrMask();
		GetOptionsMgr()->SaveOption(OPT_FILEFILTER_CURRENT, filter);
	}

	SaveComboboxStates();
	GetOptionsMgr()->SaveOption(OPT_CMP_INCLUDE_SUBDIRS, m_bRecurse);
	LoadComboboxStates();

	m_constraint.Persist(true, false);

	COpenDoc *pDoc = GetDocument();
	pDoc->m_files = m_files;
	pDoc->m_bRecurse = m_bRecurse;
	pDoc->m_strExt = m_strExt;
	pDoc->m_strUnpacker = m_strUnpacker;
	pDoc->m_infoHandler = m_infoHandler;
	pDoc->m_dwFlags[0] = m_dwFlags[0];
	pDoc->m_dwFlags[1] = m_dwFlags[1];
	pDoc->m_dwFlags[2] = m_dwFlags[2];

	if (GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_OK))
		GetParentFrame()->PostMessage(WM_CLOSE);

	GetMainFrame()->DoFileOpen(
		&PathContext(pDoc->m_files), &std::vector<DWORD>(pDoc->m_dwFlags, pDoc->m_dwFlags + 3)[0], 
		NULL, _T(""), !!pDoc->m_bRecurse, NULL, _T(""), &PackingInfo(pDoc->m_infoHandler));
}