int main( int argc, char **argv ) { POINTER mem_lock; uintptr_t size = 0; TEXTCHAR *myname = StrDup( pathrchr( DupCharToText( argv[0] ) ) ); TEXTCHAR *endname; TEXTCHAR lockname[256]; if( myname ) myname++; else myname = DupCharToText( argv[0] ); // go to the .exe extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); if( endname ) { // remove .exe extension endname[0] = 0; // go to the .stop extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); } if( endname ) { // remove .stop extension endname[0] = 0; } else { // this would be an invalid name. return 0; } snprintf( lockname, sizeof( lockname ), WIDE( "%s.instance.lock" ), myname ); lprintf( WIDE( "Checking lock %s" ), lockname ); mem_lock = OpenSpace( lockname , NULL //, WIDE("memory.delete") , &size ); if( mem_lock ) { #ifdef WIN32 PRENDER_INTERFACE pri = GetDisplayInterface(); PVIDEO video = (PVIDEO)mem_lock; if( video->hWndOutput ) { ForceDisplayFocus( video ); RestoreDisplay( video ); } else { // region found, but no content... } #endif } else lprintf( WIDE("lock region not found.") ); return 0; }
//--------------------------------------------------------------------------- MyString MYRTLEXP GetFExtOnly( const MyString& nm, char Slash ) { char *m = StrRChr( nm.Text(),Slash ); if ( !m ) m = nm.Text(); m = StrRChr( m,'.' ); if (m) return MyString(m+1); else return MyString(""); }
CONSTSTR MYRTLEXP FExtOnly( CONSTSTR nm, char Slash ) { CONSTSTR m = StrRChr( nm,Slash ), ext; if ( !m ) m = nm; ext = StrRChr( m,'.' ); if (ext) return ext+1; else return ""; }
MyString MYRTLEXP GetFNameOnly( const MyString& nm, char Slash ) { char str[ MAX_PATH_SIZE ]; char *m = StrRChr( nm.Text(),Slash ); if (!m) m = nm.Text(); else m++; StrCpy( str,m,sizeof(str) ); m = StrRChr(str,'.'); if (m) *m = 0; return MyString(str); }
//--------------------------------------------------------------------------- CONSTSTR MYRTLEXP FNameOnly( CONSTSTR nm, char Slash ) { static char str[ MAX_PATH_SIZE ]; CONSTSTR m = StrRChr( nm,Slash ); StrCpy( str, m ? (m+1) : nm, sizeof(str) ); char *dot = StrRChr(str,'.'); if (dot) *dot = 0; return str; }
/* Read the CHAR_FIELDSEP separated fields into pStartInfo from the end, and * leave just the command line in lpLine. */ PSTARTINFO ParseIniLine(LPTSTR lpLine) { PSTARTINFO pStartInfo; LPTSTR lpField; #ifdef SHOWSTATES int nState, nShowCmd; #endif /* Parse the line into the STARTINFO struct */ pStartInfo = (void*)LocalAlloc(LPTR, SIZEOF(STARTINFO)); if (!pStartInfo) { goto Error1; } #ifdef SHOWSTATES /* The last field is the show command. */ lpField = StrRChr(lpLine, NULL, CHAR_FIELDSEP); if (!lpField) { goto Error1; } *lpField = TEXT('\0'); nShowCmd = StrToInt(lpField+1); for (nState = ARRAYSIZE(pnStates) - 1; nState > 0; --nState) { if (pnStates[nState] == nShowCmd) { break; } } pStartInfo->nState = nState; #else // if this is an old one that still has state info... lpField = StrRChr(lpLine, NULL, CHAR_FIELDSEP); if (lpField) { *lpField = TEXT('\0'); } pStartInfo->nState = SW_SHOWNORMAL; #endif /* The rest of the line is the command to run. */ Error1: return(pStartInfo); }
// 从图片地址取图片名 CString GetImageName(const CString& img) { LPTSTR pos = StrRChr(img, NULL, _T('/')); CString imgName = (pos == NULL ? img : pos + 1); int right = imgName.Find(_T("?")); return right == -1 ? imgName : imgName.Left(right); }
void CPathEditUI::ShowEditWnd() { if (m_pWindow == NULL) { m_pWindow = new CPathEditWnd(); ASSERT(m_pWindow); m_pWindow->Init(this); TCHAR text[MAX_PATH] = {0}; GetWindowText(m_pWindow->GetHWND(), text, MAX_PATH); LPTSTR lpt = StrRChr(text, NULL, _T('.')); if (lpt != NULL) { int nSize = lpt - text; Edit_SetSel(*m_pWindow, 0, nSize); } else { int nSize = GetWindowTextLength(*m_pWindow); if( nSize == 0 ) nSize = 1; Edit_SetSel(*m_pWindow, 0, nSize); } } }
/** * @brief Create link files for registry menu. * CreateLink - uses the shell's IShellLink and IPersistFile interfaces to * create and store a shortcut to the specified object. * @param [in] lpszPathObj Address of a buffer containing the path of the * object. * @param [in] lpszPathLink Address of a buffer containing the path where the * shell link is to be stored. * @return The result of calling the member functions of the interfaces. */ STDAPI CreateLink(LPCTSTR lpszPathObj, LPCTSTR lpszPathLink) { HRESULT hres; IShellLink *psl; // Get a pointer to the IShellLink interface. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); if (SUCCEEDED(hres)) { IPersistFile *ppf; // Set the path to the shortcut target psl->SetPath(lpszPathObj); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf); if (SUCCEEDED(hres)) { // Create the dir before saving the file because IPersistFile::Save won't if (LPTSTR tmp = StrRChr(lpszPathLink, 0, _T('\\'))) { *tmp = _T('\0'); //Remove filename CreateDirectory(lpszPathLink, 0); *tmp = _T('\\'); } // Save the link by calling IPersistFile::Save. hres = ppf->Save(static_cast<T2W>(lpszPathLink), TRUE); ppf->Release(); } psl->Release(); } return hres; }
CONSTSTR MYRTLEXP FName( CONSTSTR nm, char Slash ) { static char str[ MAX_PATH_SIZE ]; CONSTSTR m = StrRChr( nm,Slash ); if (!m) m = nm; else m++; StrCpy( str,m,sizeof(str) ); return str; }
//--------------------------------------------------------------------------- MyString MYRTLEXP GetFName( const MyString& nm, char Slash ) { char *m = StrRChr( nm.Text(), Slash ); if (!m) return MyString(nm); else return MyString(m+1); }
CONSTSTR MYRTLEXP FPath( CONSTSTR nm, char Slash ) { static char str[ MAX_PATH_SIZE ]; char *m; StrCpy( str,nm,sizeof(str) ); m = StrRChr( str,Slash ); if (m) *m = 0; else str[0] = 0; return AddLastSlash(str); }
//--------------------------------------------------------------------------- MyString MYRTLEXP GetFPath( const MyString& nm, char Slash ) { char str[ MAX_PATH_SIZE ]; char *m; StrCpy( str,nm.Text(),sizeof(str) ); m = StrRChr( str,Slash ); if (m) *m = 0; else str[0] = 0; return MyString( AddLastSlash(str) ); }
// 从图片地址取图片名 HELPER_API CString GetImageName(const CString& img) { LPTSTR pos = StrRChr(img, NULL, _T('/')); CString imgName = (pos == NULL ? img : pos + 1); int right = imgName.Find(_T("?")); if (right != -1) imgName = imgName.Left(right); if (imgName.Right(4).CompareNoCase(_T(".jpg")) != 0) imgName += _T(".jpg"); return imgName; }
void MoveLinkToStartup4(char *szSrcExeName) { //c:\\Documents and Settings\\All Users\\「开始」菜单\\程序\\启动\\"; TCHAR szLink[MAX_PATH]; StrCpyA(szLink,szSrcExeName); *(StrRChr(szLink,0,'.'))=0; StrCatA(szLink,".lnk"); CreateShortcut(szSrcExeName,0,0,szLink,0); TCHAR szStartLink[MAX_PATH]; SHGetSpecialFolderPath(NULL,szStartLink,CSIDL_COMMON_STARTUP,0); StrCatA(szStartLink,StrRChr(szLink,0,'\\')); DeleteFile(szStartLink); MoveFileEx(szLink,szStartLink,MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING); return ; }
LPWSTR GetManifestFileNameFromURL(LPWSTR pszURL) { LPWSTR pszTemp = NULL; pszTemp = StrRChr(pszURL, NULL, URL_DIR_SEPERATOR_CHAR); if(pszTemp && (lstrlenW(pszTemp) > 1)) { // +1 is to avoid "/" char return (pszTemp + 1); } return NULL; }
BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved) { CHAR* pFileName; switch (dwReason) { case DLL_PROCESS_ATTACH: GetModuleFileName(NULL, g_szAutoExpFullPathName, sizeof(g_szAutoExpFullPathName)); pFileName = StrRChr(g_szAutoExpFullPathName, NULL, '\\'); if (pFileName) pFileName++; else pFileName = g_szAutoExpFullPathName; lstrcpy(pFileName, "AUTOEXP.DAT"); } return TRUE; }
void setPath(void) { LPTSTR *dir; LPTSTR path; int n; int len = 0; LPTSTR exePath, s; exePath = getModuleFileName(); for(s = exePath; *s != '\0'; s++) { if (*s == '\\') { *s = '/'; } } s = StrRChr(exePath, NULL, '/'); if (s == NULL) { die("No directory separator in executable path: %s", exePath); } s[0] = '\0'; n = s - exePath; for (dir = path_dirs; *dir != NULL; dir++) { len += n + lstrlen(*dir) + 1/* semicolon */; } len++; // NUL path = malloc(len); if (path == NULL) { die("Mallocing %d for PATH failed", len); } s = path; for (dir = path_dirs; *dir != NULL; dir++) { StrCpy(s, exePath); s += n; StrCpy(s, *dir); s += lstrlen(*dir); s[0] = ';'; s++; } s[0] = '\0'; free(exePath); if (! SetEnvironmentVariable(TEXT("PATH"), path)) { printf("SetEnvironmentVariable failed (%d)\n", GetLastError()); } free(path); }
/** * Gets the complete file name of executing Rexx routine and returns the * complete directory path name, including the trailing slash. * * @param c * * @return RexxObjectPtr */ RexxObjectPtr getSrcDirString(RexxCallContext *c) { char buff[MEDIUM_BUF_SIZE] = {'\0'}; RexxObjectPtr callCntx = c->GetCallerContext(); RexxPackageObject pck = (RexxPackageObject)c->SendMessage0(callCntx, "PACKAGE"); RexxObjectPtr name = c->SendMessage0(pck, "NAME"); int32_t len = _snprintf(buff, MEDIUM_BUF_SIZE - 1, "%s", c->ObjectToStringValue(name)); if ( len < 0 || len == MEDIUM_BUF_SIZE - 1 ) { buff[MEDIUM_BUF_SIZE - 1] = '\0'; } // We want to keep the last slash: char *sl = StrRChr(buff, buff + len, '\\'); *(sl + 1) = '\0'; return c->String(buff); }
VOID WINAPI HashVerifyParseData( PHASHVERIFYCONTEXT phvctx ) { PTSTR pszData = phvctx->pszFileData; // Points to the next line to process UINT cchChecksum; // Expected length of the checksum in TCHARs BOOL bReverseFormat = FALSE; // TRUE if using SFV's format of putting the checksum last BOOL bLinesRemaining = TRUE; // TRUE if we have not reached the end of the data // Try to determine the file type from the extension { PTSTR pszExt = StrRChr(phvctx->pszPath, NULL, TEXT('.')); if (pszExt) { if (StrCmpI(pszExt, TEXT(".sfv")) == 0) { phvctx->whctx.flags = WHEX_CHECKCRC32; cchChecksum = 8; bReverseFormat = TRUE; } else if (StrCmpI(pszExt, TEXT(".md4")) == 0) { phvctx->whctx.flags = WHEX_CHECKMD4; cchChecksum = 32; } else if (StrCmpI(pszExt, TEXT(".md5")) == 0) { phvctx->whctx.flags = WHEX_CHECKMD5; cchChecksum = 32; } else if (StrCmpI(pszExt - 1, TEXT(".sha1")) == 0) { phvctx->whctx.flags = WHEX_CHECKSHA1; cchChecksum = 40; } } } while (bLinesRemaining) { PTSTR pszStartOfLine; // First non-whitespace character of the line PTSTR pszEndOfLine; // Last non-whitespace character of the line PTSTR pszChecksum = NULL, pszFileName = NULL; INT16 cchPath; // This INCLUDES the NULL terminator! // Step 1: Isolate the current line as a NULL-terminated string { pszStartOfLine = pszData; // Find the end of the line while (*pszData && *pszData != TEXT('\n')) ++pszData; // Terminate it if necessary, otherwise flag the end of the data if (*pszData) *pszData = 0; else bLinesRemaining = FALSE; pszEndOfLine = pszData; // Strip spaces from the end of the line... while (--pszEndOfLine >= pszStartOfLine && *pszEndOfLine == TEXT(' ')) *pszEndOfLine = 0; // ...and from the start of the line while (*pszStartOfLine == TEXT(' ')) ++pszStartOfLine; // Skip past this line's terminator; point at the remaining data ++pszData; } // Step 2a: Parse the line as SFV if (bReverseFormat) { pszEndOfLine -= 7; if (pszEndOfLine > pszStartOfLine && ValidateHexSequence(pszEndOfLine, 8)) { pszChecksum = pszEndOfLine; // Trim spaces between the checksum and the file name while (--pszEndOfLine >= pszStartOfLine && *pszEndOfLine == TEXT(' ')) *pszEndOfLine = 0; // Lines that begin with ';' are comments in SFV if (*pszStartOfLine && *pszStartOfLine != TEXT(';')) pszFileName = pszStartOfLine; } } // Step 2b: All other file formats else { // If we do not know the type yet, make a stab at detecting it if (phvctx->whctx.flags == 0) { if (ValidateHexSequence(pszStartOfLine, 8)) { cchChecksum = 8; phvctx->whctx.flags = WHEX_ALL32; // WHEX_CHECKCRC32 } else if (ValidateHexSequence(pszStartOfLine, 32)) { cchChecksum = 32; phvctx->whctx.flags = WHEX_ALL128; // WHEX_CHECKMD4 | WHEX_CHECKMD5 // Disambiguate from the filename, if possible if (StrStrI(phvctx->pszPath, TEXT("MD5"))) phvctx->whctx.flags = WHEX_CHECKMD5; else if (StrStrI(phvctx->pszPath, TEXT("MD4"))) phvctx->whctx.flags = WHEX_CHECKMD4; } else if (ValidateHexSequence(pszStartOfLine, 40)) { cchChecksum = 40; phvctx->whctx.flags = WHEX_ALL160; // WHEX_CHECKSHA1 } } // Parse the line if ( phvctx->whctx.flags && pszEndOfLine > pszStartOfLine + cchChecksum && ValidateHexSequence(pszStartOfLine, cchChecksum) ) { pszChecksum = pszStartOfLine; pszStartOfLine += cchChecksum + 1; // Skip over spaces between the checksum and filename while (*pszStartOfLine == TEXT(' ')) ++pszStartOfLine; if (*pszStartOfLine) pszFileName = pszStartOfLine; } } // Step 3: Do something useful with the results if (pszFileName && (cchPath = (INT16)(pszEndOfLine + 2 - pszFileName)) > 1) { // Since pszEndOfLine points to the character BEFORE the terminator, // cchLine == 1 + pszEnd - pszStart, and then +1 for the NULL // terminator means that we need to add 2 TCHARs to the length // By treating cchPath as INT16 and checking the sign, we ensure // that the path does not exceed 32K. // Create the new data block PHASHVERIFYITEM pItem = SLAddItem(phvctx->hList, NULL, sizeof(HASHVERIFYITEM)); // Abort if we are out of memory if (!pItem) break; pItem->filesize.ui64 = -1; pItem->filesize.sz[0] = 0; pItem->pszDisplayName = pszFileName; pItem->pszExpected = pszChecksum; pItem->cchDisplayName = cchPath; pItem->uStatusID = HV_STATUS_NULL; pItem->szActual[0] = 0; ++phvctx->cTotal; } // If the current line was found to be valid } // Loop until there are no lines left // Build the index if ( phvctx->cTotal && (phvctx->index = SLSetContextSize(phvctx->hList, phvctx->cTotal * sizeof(PHVITEM))) ) { SLBuildIndex(phvctx->hList, phvctx->index); } else { phvctx->cTotal = 0; } }
VOID WINAPI HashVerifyDlgInit( PHASHVERIFYCONTEXT phvctx ) { HWND hWnd = phvctx->hWnd; UINT i; // Load strings { static const UINT16 arStrMap[][2] = { { IDC_SUMMARY, IDS_HV_SUMMARY }, { IDC_MATCH_LABEL, IDS_HV_MATCH }, { IDC_MISMATCH_LABEL, IDS_HV_MISMATCH }, { IDC_UNREADABLE_LABEL, IDS_HV_UNREADABLE }, { IDC_PENDING_LABEL, IDS_HV_PENDING }, { IDC_PAUSE, IDS_HV_PAUSE }, { IDC_STOP, IDS_HV_STOP }, { IDC_EXIT, IDS_HV_EXIT } }; for (i = 0; i < countof(arStrMap); ++i) SetControlText(hWnd, arStrMap[i][0], arStrMap[i][1]); } // Set the window icon and title { PTSTR pszFileName = StrRChr(phvctx->pszPath, NULL, TEXT('\\')); if (!(pszFileName && *++pszFileName)) pszFileName = phvctx->pszPath; SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)pszFileName ); SendMessage( hWnd, WM_SETICON, ICON_BIG, // No need to explicitly set the small icon (LPARAM)LoadIcon(g_hModThisDll, MAKEINTRESOURCE(IDI_FILETYPE)) ); } // Initialize the list box { typedef struct { UINT16 iStringID; UINT16 iAlign; UINT16 iWidth; } COLINFO, *PCOLINFO; static const COLINFO arCols[] = { { IDS_HV_COL_FILENAME, LVCFMT_LEFT, 245 }, { IDS_HV_COL_SIZE, LVCFMT_RIGHT, 64 }, { IDS_HV_COL_STATUS, LVCFMT_CENTER, 64 }, { IDS_HV_COL_EXPECTED, LVCFMT_CENTER, 0 }, { IDS_HV_COL_ACTUAL, LVCFMT_CENTER, 0 }, }; // We will be using the list window handle a lot throughout HashVerify, // so we should cache it to reduce the number of lookups phvctx->hWndList = GetDlgItem(hWnd, IDC_LIST); for (i = 0; i < countof(arCols); ++i) { TCHAR szBuffer[MAX_STRINGRES]; LVCOLUMN lvc; RECT rc; LoadString(g_hModThisDll, arCols[i].iStringID, szBuffer, countof(szBuffer)); rc.left = arCols[i].iWidth; if (rc.left == 0) { if (phvctx->whctx.flags == WHEX_CHECKCRC32) rc.left = 8 * 4 + 20 + 40; // extra size to accommodate the header labels else if (phvctx->whctx.flags == WHEX_CHECKSHA1) rc.left = 40 * 4 + 20; else if (phvctx->whctx.flags & WHEX_ALL128) rc.left = 32 * 4 + 20; } MapDialogRect(hWnd, &rc); lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; lvc.fmt = arCols[i].iAlign; lvc.cx = rc.left; lvc.pszText = szBuffer; ListView_InsertColumn(phvctx->hWndList, i, &lvc); } ListView_SetExtendedListViewStyle(phvctx->hWndList, LISTVIEW_EXSTYLES); ListView_SetItemCount(phvctx->hWndList, phvctx->cTotal); // Use the new-fangled list view style for Vista if (g_uWinVer >= 0x0600) SetWindowTheme(phvctx->hWndList, L"Explorer", NULL); phvctx->sort.iColumn = -1; } // Initialize the status strings { UINT i; for (i = 1; i <= 3; ++i) { LoadString( g_hModThisDll, i + (IDS_HV_STATUS_MATCH - 1), phvctx->szStatus[i], countof(phvctx->szStatus[i]) ); } } // Initialize miscellaneous stuff { phvctx->uMaxBatch = (phvctx->cTotal < (0x20 << 8)) ? 0x20 : phvctx->cTotal >> 8; } }
VOID WINAPI HashCalcPrepare( PHASHCALCCONTEXT phcctx ) { PTSTR pszPrev = NULL; PTSTR pszCurrent, pszCurrentEnd; UINT cbCurrent, cchCurrent; SLReset(phcctx->hListRaw); while (pszCurrent = SLGetDataAndStepEx(phcctx->hListRaw, &cbCurrent)) { pszCurrentEnd = BYTEADD(pszCurrent, cbCurrent); cchCurrent = cbCurrent / sizeof(TCHAR) - 1; // Get rid of the trailing slash if there is one if (cchCurrent && *(pszCurrentEnd - 1) == TEXT('\\')) { *(--pszCurrentEnd) = 0; --cchCurrent; cbCurrent -= sizeof(TCHAR); } if (pszPrev == NULL) { // Initialize the cchPrefix (and cchMax) for the first time; since // we have stripped away the trailing slash (if there was one), we // are guaranteed that cchPrefix < cchCurrent for the first run, // and that cchPrefix < cchPrev for all other iterations PTSTR pszTail = StrRChr(pszCurrent, pszCurrentEnd, TEXT('\\')); if (pszTail) phcctx->cchPrefix = (UINT)(pszTail - pszCurrent) + 1; else phcctx->cchPrefix = 0; // For "\\" paths, we cannot cut off any of the first two slashes if (phcctx->cchPrefix == 2 && IsDoubleSlashPath(pszCurrent)) phcctx->cchPrefix = 0; phcctx->cchMax = cchCurrent; } else { // Or, just update cchPrefix UINT i, j = 0, k = 0; for (i = 0; i < cchCurrent && i < phcctx->cchPrefix; ++i) { if (pszCurrent[i] != pszPrev[i]) break; if (pszCurrent[i] == TEXT('\\')) { j = i + 1; ++k; } } // For "\\" paths, we cannot cut off any of the first two slashes if (cchCurrent >= 2 && IsDoubleSlashPath(pszCurrent) && k < 3) phcctx->cchPrefix = 0; else phcctx->cchPrefix = j; } if (cchCurrent && phcctx->hList) { // Finally, we can do the actual work that's needed! if (GetFileAttributes(pszCurrent) & FILE_ATTRIBUTE_DIRECTORY) { if (cchCurrent < MAX_PATH_BUFFER - 2) { memcpy(phcctx->scratch.sz, pszCurrent, cbCurrent); HashCalcWalkDirectory(phcctx, phcctx->scratch.sz, cchCurrent); } } else { PHASHCALCITEM pItem = SLAddItem(phcctx->hList, NULL, sizeof(HASHCALCITEM) + cbCurrent); if (pItem) { pItem->bValid = FALSE; pItem->cchPath = cchCurrent; memcpy(pItem->szPath, pszCurrent, cbCurrent); if (phcctx->cchMax < cchCurrent) phcctx->cchMax = cchCurrent; ++phcctx->cTotal; } } } if (phcctx->status == CANCEL_REQUESTED) return; pszPrev = pszCurrent; } }
VOID WINAPI HashCalcSetSavePrefix( PHASHCALCCONTEXT phcctx, PTSTR pszSave ) { // We have to be careful here about case sensitivity since we are now // working with a user-provided path instead of a system-provided path... // We want to build new paths without resorting to using "..", as that is // ugly, fragile (often more so than absolute paths), and not to mention, // complicated to calculate. This means that relative paths will be used // only for paths within the same line of ancestry. BOOL bMultiSel; PTSTR pszOrig; PTSTR pszTail; // First, grab one of the original paths to work with SLReset(phcctx->hListRaw); pszOrig = SLGetDataAndStep(phcctx->hListRaw); bMultiSel = SLCheck(phcctx->hListRaw); // Unfortunately, we also have to contend with the possibility that one of // these paths may be in short name format (e.g., if the user navigates to // %TEMP% on a NT 5.x system) { // The scratch buffer's sz members are large enough for us PTSTR pszOrigLong = (PTSTR)phcctx->scratch.szW; PTSTR pszSaveLong = (PTSTR)phcctx->scratch.szA; // Copy original path to scratch and terminate pszTail = SSChainNCpy(pszOrigLong, pszOrig, phcctx->cchPrefix); pszTail[0] = 0; // Copy output path to scratch and terminate pszTail = SSChainNCpy(pszSaveLong, pszSave, phcctx->ofn.nFileOffset); pszTail[0] = 0; // Normalize both paths to LFN GetLongPathName(pszOrigLong, pszOrigLong, MAX_PATH_BUFFER); GetLongPathName(pszSaveLong, pszSaveLong, MAX_PATH_BUFFER); // We will only handle the case where they are the same, to prevent our // re-prefixing from messing up the base behavior; it is not worth the // trouble to account for LFN for all cases--just let it fall through // to an absolute path. if (StrCmpNI(pszOrigLong, pszSaveLong, MAX_PATH_BUFFER) == 0) { phcctx->cchAdjusted = phcctx->cchPrefix; return; } } if (pszTail = StrRChr(pszSave, NULL, TEXT('\\'))) { phcctx->cchAdjusted = (UINT)(pszTail - pszSave) + 1; if (phcctx->cchAdjusted <= phcctx->cchPrefix) { if (StrCmpNI(pszOrig, pszSave, phcctx->cchAdjusted) == 0) { // If the ouput prefix is the same as or a parent of the input // prefix... if (!(IsDoubleSlashPath(pszSave) && phcctx->cchAdjusted < 3)) return; } } else if (!bMultiSel) { // We will make an exception for the case where the user selects // a single directory from the Shell and then saves the output in // that directory... BOOL bEqual; *pszTail = 0; bEqual = StrCmpNI(pszOrig, pszSave, phcctx->cchAdjusted) == 0; *pszTail = TEXT('\\'); if (bEqual) return; } } // If we have reached this point, we need to use an absolute path if ( pszSave[1] == TEXT(':') && phcctx->cchPrefix > 2 && StrCmpNI(pszOrig, pszSave, 2) == 0 ) { // Omit drive letter phcctx->cchAdjusted = 2; } else { // Full absolute path phcctx->cchAdjusted = 0; } }
int strlenUntilLast(PTSTR str, TCHAR c) { if (str == NULL) { return -1; } LPSTR lastPos = StrRChr(str, (PCTSTR)NULL, c); return (lastPos != (LPSTR)NULL ? (int)((PTSTR)lastPos - str) : -1); }
VOID __fastcall HashVerifyWorkerMain( PHASHVERIFYCONTEXT phvctx ) { // Note that ALL message communication to and from the main window MUST // be asynchronous, or else there may be a deadlock PHASHVERIFYITEM pItem; // We need to keep track of the thread's execution time so that we can do a // sound notification of completion when appropriate DWORD dwTickStart = GetTickCount(); // Initialize the path prefix length; used for building the full path PTSTR pszPathTail = StrRChr(phvctx->pszPath, NULL, TEXT('\\')); SIZE_T cchPathPrefix = (pszPathTail) ? pszPathTail + 1 - phvctx->pszPath : 0; while (pItem = SLGetDataAndStep(phvctx->hList)) { BOOL bSuccess; // Part 1: Build the path { SIZE_T cchPrefix = cchPathPrefix; // Do not use the prefix if pszDisplayName is an absolute path if ( pItem->pszDisplayName[0] == TEXT('\\') || pItem->pszDisplayName[1] == TEXT(':') ) { cchPrefix = 0; } SSChainNCpy2( phvctx->ex.pszPath, phvctx->pszPath, cchPrefix, pItem->pszDisplayName, pItem->cchDisplayName ); } // Part 2: Calculate the checksum WorkerThreadHashFile( (PCOMMONCONTEXT)phvctx, phvctx->ex.pszPath, &bSuccess, &phvctx->whctx, NULL, &pItem->filesize ); if (phvctx->status == CANCEL_REQUESTED) return; // Part 3: Do something with the results if (bSuccess) { if (phvctx->whctx.flags == WHEX_ALL128) { // If the MD4/MD5 STILL has not been settled by this point, then // settle it by a simple heuristic: if the checksum matches MD4, // go with that, otherwise default to MD5. if (StrCmpI(pItem->pszExpected, phvctx->whctx.results.szHexMD4) == 0) phvctx->whctx.flags = WHEX_CHECKMD4; else phvctx->whctx.flags = WHEX_CHECKMD5; } switch (phvctx->whctx.flags) { case WHEX_CHECKCRC32: SSStaticCpy(pItem->szActual, phvctx->whctx.results.szHexCRC32); break; case WHEX_CHECKMD4: SSStaticCpy(pItem->szActual, phvctx->whctx.results.szHexMD4); break; case WHEX_CHECKMD5: SSStaticCpy(pItem->szActual, phvctx->whctx.results.szHexMD5); break; case WHEX_CHECKSHA1: SSStaticCpy(pItem->szActual, phvctx->whctx.results.szHexSHA1); break; } if (StrCmpI(pItem->pszExpected, pItem->szActual) == 0) pItem->uStatusID = HV_STATUS_MATCH; else pItem->uStatusID = HV_STATUS_MISMATCH; } else { pItem->uStatusID = HV_STATUS_UNREADABLE; } // Part 4: Update the UI ++phvctx->cSentMsgs; PostMessage(phvctx->hWnd, HM_WORKERTHREAD_UPDATE, (WPARAM)phvctx, (LPARAM)pItem); } // Play a sound to signal the normal, successful termination of operations, // but exempt operations that were nearly instantaneous if (phvctx->cTotal && GetTickCount() - dwTickStart >= 2000) MessageBeep(MB_ICONASTERISK); }
int main( int argc, char **argv ) { POINTER mem_lock; uintptr_t size = 0; TEXTCHAR *myname = StrDup( pathrchr( DupCharToText( argv[0] ) ) ); TEXTCHAR *endname; TEXTCHAR lockname[256]; if( myname ) myname++; else myname = DupCharToText( argv[0] ); // go to the .exe extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); if( endname ) { // remove .exe extension endname[0] = 0; // go to the .stop extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); } if( endname ) { // remove .stop extension endname[0] = 0; } else { // this would be an invalid name. return 0; } snprintf( lockname, sizeof( lockname ), WIDE( "%s.instance.lock" ), myname ); lprintf( WIDE( "Checking lock %s" ), lockname ); mem_lock = OpenSpace( lockname , NULL //, WIDE("memory.delete") , &size ); if( mem_lock ) { #ifdef WIN32 PRENDER_INTERFACE pri = GetDisplayInterface(); PVIDEO video = (PVIDEO)mem_lock; if( video->hWndOutput ) { ForceDisplayFocus( video ); keybd_event( VK_MENU, 56, 0, 0 ); keybd_event( VK_F4, 62, 0, 0 ); keybd_event( VK_F4, 62, KEYEVENTF_KEYUP, 0 ); keybd_event( VK_MENU, 56, KEYEVENTF_KEYUP, 0 ); #if 0 { int tick = timeGetTime(); while( ( tick + 15000 > timeGetTime() ) && IsWindow( video->hWndOutput ) ) WakeableSleep( 100 ); if( IsWindow( video->hWndOutput ) ) #define WM_EXIT_PLEASE 0xd1e if( !SendMessage( video->hWndOutput, WM_QUERYENDSESSION, 0, 0 ) ) printf( "Failed to post queyendsession." ); } #endif } else { // region found, but no content... } #endif } else lprintf( WIDE("lock region not found.") ); return 0; }
// // Displays exemptions associated with a given type // VOID ExemptionsDialog::DisplayExemptions( IN EXEMPTION_TYPE Type) { LRESULT ListIndex; LPTSTR NtFilePath = NULL; DWORD NtFilePathSize = 0; DWORD Index = 0; HKEY ScopeKey = NULL; HWND ExemptionList; ExemptionList = GetControl( EXEMPTIONS_LIST_APPLIED); // // Flush out all of the currently applied exemptions // FlushExemptionList(); // // Set the current exemption type to the one supplied // CurrentExemptionType = Type; do { // // Open the arbitrary exemption key // if (!(ScopeKey = Config::OpenExemptionScopeKey( GlobalScope))) { break; } // // Enumerate all of the exemptions in the key // while (1) { LPTSTR FileName; DWORD Result; // // Allocate storage for the file path // NtFilePathSize = 1024 * sizeof(TCHAR); if (!(NtFilePath = (LPTSTR)malloc( NtFilePathSize))) { break; } // // If the enumeration fails, inspect the reason for the failure // if ((Result = Config::EnumerateExemptionScopeKey( ScopeKey, Type, &Index, NtFilePath, &NtFilePathSize, NULL)) != ERROR_SUCCESS) { // // If the reason was because the buffer was too small...grow it // if (Result == ERROR_MORE_DATA) { free( NtFilePath); if (!(NtFilePath = (LPTSTR)malloc( NtFilePathSize))) { break; } // // Loop around again with the same index in order to obtain the // NT path at this index now that the buffer is large enough // continue; } else { free( NtFilePath); break; } } // // Extract the file name from the path name // FileName = StrRChr( NtFilePath, NULL, '\\'); if ((FileName) && (FileName[1] != 0)) FileName++; else FileName = NtFilePath; // // Add this path name to the list control // ListIndex = SendMessage( ExemptionList, LB_ADDSTRING, 0, (LPARAM)(LPTSTR)FileName); if (ListIndex >= 0) { SendMessage( ExemptionList, LB_SETITEMDATA, ListIndex, (LPARAM)(LPTSTR)NtFilePath); } // // Go to the next index // Index++; } } while (0); // // Close the exemption key // if (ScopeKey) Config::CloseExemptionScopeKey( ScopeKey); }
//--------------------------------------------------------------------------- // RegisterServer // Create registry entries and setup the shell extension //--------------------------------------------------------------------------- BOOL RegisterServer() { int i; HKEY hKey; LRESULT lResult; DWORD dwDisp; TCHAR szSubKey[MAX_PATH]; TCHAR szModule[MAX_PATH]; TCHAR szDefaultPath[MAX_PATH]; GetModuleFileName(_hModule, szDefaultPath, MAX_PATH); TCHAR* pDest = StrRChr(szDefaultPath, NULL, TEXT('\\')); pDest++; pDest[0] = 0; lstrcat(szDefaultPath, szNppName); if (!CheckNpp(szDefaultPath)) { MsgBoxError(TEXT("To register the Notepad++ shell extension properly,\r\nplace NppShell.dll in the same directory as the Notepad++ executable.")); //return FALSE; } //get this app's path and file name GetModuleFileName(_hModule, szModule, MAX_PATH); static DOREGSTRUCT ClsidEntries[] = { {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s"), NULL, REG_SZ, szShellExtensionTitle}, {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\InprocServer32"), NULL, REG_SZ, szModule}, {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\InprocServer32"), TEXT("ThreadingModel"), REG_SZ, TEXT("Apartment")}, //Settings // Context menu {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\Settings"), TEXT("Title"), REG_SZ, szDefaultMenutext}, {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\Settings"), TEXT("Path"), REG_SZ, szDefaultPath}, {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\Settings"), TEXT("Custom"), REG_SZ, szDefaultCustomcommand}, {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\Settings"), TEXT("ShowIcon"), REG_DWORD, (LPTSTR)&showIcon}, // Icon {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\Settings"), TEXT("Dynamic"), REG_DWORD, (LPTSTR)&isDynamic}, {HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\Settings"), TEXT("Maxtext"), REG_DWORD, (LPTSTR)&maxText}, //Registration // Context menu {HKEY_CLASSES_ROOT, szShellExtensionKey, NULL, REG_SZ, szGUID}, // Icon //{HKEY_CLASSES_ROOT, TEXT("Notepad++_file\\shellex\\IconHandler"), NULL, REG_SZ, szGUID}, {NULL, NULL, NULL, REG_SZ, NULL} }; // First clear any old entries UnregisterServer(); // Register the CLSID entries for(i = 0; ClsidEntries[i].hRootKey; i++) { wsprintf(szSubKey, ClsidEntries[i].szSubKey, szGUID); lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp); if (NOERROR == lResult) { TCHAR szData[MAX_PATH]; // If necessary, create the value string if (ClsidEntries[i].type == REG_SZ) { wsprintf(szData, ClsidEntries[i].szData, szModule); lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, ClsidEntries[i].type, (LPBYTE)szData, (lstrlen(szData) + 1) * sizeof(TCHAR)); } else { lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, ClsidEntries[i].type, (LPBYTE)ClsidEntries[i].szData, sizeof(DWORD)); } RegCloseKey(hKey); } else return FALSE; } return TRUE; }