本文整理汇总了C++中GetFullPathName函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFullPathName函数的具体用法?C++ GetFullPathName怎么用?C++ GetFullPathName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetFullPathName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeleteFiles
static DWORD
DeleteFiles(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
{
TCHAR szFullPath[MAX_PATH];
TCHAR szFileName[MAX_PATH];
LPTSTR pFilePart;
HANDLE hFile;
WIN32_FIND_DATA f;
BOOL bExclusion;
INT res;
DWORD dwFiles = 0;
_tcscpy(szFileName, FileName);
if(_tcschr (szFileName, _T('*')) == NULL &&
IsExistingDirectory (szFileName))
{
/* If it doesnt have a \ at the end already then on needs to be added */
if(szFileName[_tcslen(szFileName) - 1] != _T('\\'))
_tcscat (szFileName, _T("\\"));
/* Add a wildcard after the \ */
_tcscat (szFileName, _T("*"));
}
if(!_tcscmp (szFileName, _T("*")) ||
!_tcscmp (szFileName, _T("*.*")) ||
(szFileName[_tcslen(szFileName) - 2] == _T('\\') && szFileName[_tcslen(szFileName) - 1] == _T('*')))
{
/* well, the user wants to delete everything but if they didnt yes DEL_YES, DEL_QUIET, or DEL_PROMPT
then we are going to want to make sure that in fact they want to do that. */
if (!((*dwFlags & DEL_YES) || (*dwFlags & DEL_QUIET) || (*dwFlags & DEL_PROMPT)))
{
res = FilePromptYNA (STRING_DEL_HELP2);
if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
return 0x80000000;
if(res == PROMPT_ALL)
*dwFlags |= DEL_YES;
}
}
GetFullPathName (szFileName,
MAX_PATH,
szFullPath,
&pFilePart);
hFile = FindFirstFile(szFullPath, &f);
if (hFile != INVALID_HANDLE_VALUE)
{
do
{
bExclusion = FALSE;
/*if it is going to be excluded by - no need to check attrs*/
if(*dwFlags & DEL_ATTRIBUTES && !bExclusion)
{
/*save if file attr check if user doesnt care about that attr anyways*/
if(dwAttrFlags & ATTR_ARCHIVE && !(f.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE))
bExclusion = TRUE;
if(dwAttrFlags & ATTR_HIDDEN && !(f.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
bExclusion = TRUE;
if(dwAttrFlags & ATTR_SYSTEM && !(f.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM))
bExclusion = TRUE;
if(dwAttrFlags & ATTR_READ_ONLY && !(f.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
bExclusion = TRUE;
if(dwAttrFlags & ATTR_N_ARCHIVE && (f.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE))
bExclusion = TRUE;
if(dwAttrFlags & ATTR_N_HIDDEN && (f.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
bExclusion = TRUE;
if(dwAttrFlags & ATTR_N_SYSTEM && (f.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM))
bExclusion = TRUE;
if(dwAttrFlags & ATTR_N_READ_ONLY && (f.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
bExclusion = TRUE;
}
if(bExclusion)
continue;
/* ignore directories */
if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
_tcscpy (pFilePart, f.cFileName);
/* We cant delete ourselves */
if(!_tcscmp (CMDPath,szFullPath))
continue;
TRACE("Full filename: %s\n", debugstr_aw(szFullPath));
/* ask for deleting */
if (*dwFlags & DEL_PROMPT)
{
ConErrResPrintf(STRING_DEL_ERROR5, szFullPath);
res = FilePromptYN (STRING_DEL_ERROR6);
if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
//.........这里部分代码省略.........
示例2: ConfigFileName
InspIRCd::InspIRCd(int argc, char** argv) :
ConfigFileName(INSPIRCD_CONFIG_PATH "/inspircd.conf"),
PI(&DefaultProtocolInterface),
/* Functor pointer initialisation.
*
* THIS MUST MATCH THE ORDER OF DECLARATION OF THE FUNCTORS, e.g. the methods
* themselves within the class.
*/
GenRandom(&DefaultGenRandom),
IsChannel(&DefaultIsChannel),
IsNick(&DefaultIsNick),
IsIdent(&DefaultIsIdent)
{
ServerInstance = this;
FailedPortList pl;
// Flag variables passed to getopt_long() later
int do_version = 0, do_nofork = 0, do_debug = 0,
do_nolog = 0, do_nopid = 0, do_root = 0;
// Initialize so that if we exit before proper initialization they're not deleted
this->Config = 0;
this->XLines = 0;
this->ConfigThread = NULL;
this->FakeClient = NULL;
UpdateTime();
this->startup_time = TIME.tv_sec;
SocketEngine::Init();
this->Config = new ServerConfig;
dynamic_reference_base::reset_all();
this->XLines = new XLineManager;
this->Config->cmdline.argv = argv;
this->Config->cmdline.argc = argc;
#ifdef _WIN32
srand(TIME.tv_nsec ^ TIME.tv_sec);
// Initialize the console values
g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO bufinf;
if(GetConsoleScreenBufferInfo(g_hStdout, &bufinf))
{
g_wOriginalColors = bufinf.wAttributes & 0x00FF;
g_wBackgroundColor = bufinf.wAttributes & 0x00F0;
}
else
{
g_wOriginalColors = FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN;
g_wBackgroundColor = 0;
}
#else
srandom(TIME.tv_nsec ^ TIME.tv_sec);
#endif
{
ServiceProvider* provs[] =
{
&rfcevents.numeric, &rfcevents.join, &rfcevents.part, &rfcevents.kick, &rfcevents.quit, &rfcevents.nick,
&rfcevents.mode, &rfcevents.topic, &rfcevents.privmsg, &rfcevents.invite, &rfcevents.ping, &rfcevents.pong,
&rfcevents.error
};
Modules.AddServices(provs, sizeof(provs)/sizeof(provs[0]));
}
struct option longopts[] =
{
{ "nofork", no_argument, &do_nofork, 1 },
{ "config", required_argument, NULL, 'c' },
{ "debug", no_argument, &do_debug, 1 },
{ "nolog", no_argument, &do_nolog, 1 },
{ "nopid", no_argument, &do_nopid, 1 },
{ "runasroot", no_argument, &do_root, 1 },
{ "version", no_argument, &do_version, 1 },
#ifdef INSPIRCD_ENABLE_TESTSUITE
{ "testsuite", no_argument, &do_testsuite, 1 },
#endif
{ 0, 0, 0, 0 }
};
int c;
int index;
while ((c = getopt_long(argc, argv, ":c:", longopts, &index)) != -1)
{
switch (c)
{
case 'c':
/* Config filename was set */
ConfigFileName = optarg;
#ifdef _WIN32
TCHAR configPath[MAX_PATH + 1];
if (GetFullPathName(optarg, MAX_PATH, configPath, NULL) > 0)
ConfigFileName = configPath;
#else
char configPath[PATH_MAX + 1];
if (realpath(optarg, configPath))
//.........这里部分代码省略.........
示例3: find_file_helper
int find_file_helper(char *includepath, char *origin, char *includefolder, char *actualpath, char *cwd) {
/*
* Finds the file referenced in includepath in the includefolder. origin
* describes the file in which the include is used (used for relative
* includes). actualpath holds the return pointer. The 4th arg is used for
* recursion on Windows and should be passed as NULL initially.
*
* Returns 0 on success, 1 on error and 2 if no file could be found.
*
* Please note that relative includes always return a path, even if that
* file does not exist.
*/
// relative include, this shit is easy
if (includepath[0] != '\\') {
strncpy(actualpath, origin, 2048);
char *target = actualpath + strlen(actualpath) - 1;
while (*target != PATHSEP)
target--;
strncpy(target + 1, includepath, 2046 - (target - actualpath));
#ifndef _WIN32
int i;
for (i = 0; i < strlen(actualpath); i++) {
if (actualpath[i] == '\\')
actualpath[i] = '/';
}
#endif
return 0;
}
char filename[2048];
char *ptr = includepath + strlen(includepath);
while (*ptr != '\\')
ptr--;
ptr++;
strncpy(filename, ptr, 2048);
#ifdef _WIN32
if (cwd == NULL)
return find_file_helper(includepath, origin, includefolder, actualpath, includefolder);
WIN32_FIND_DATA file;
HANDLE handle = NULL;
char mask[2048];
GetFullPathName(includefolder, 2048, includefolder, NULL);
GetFullPathName(cwd, 2048, mask, NULL);
sprintf(mask, "%s\\*", mask);
handle = FindFirstFile(mask, &file);
if (handle == INVALID_HANDLE_VALUE)
return 1;
do {
if (strcmp(file.cFileName, ".") == 0 || strcmp(file.cFileName, "..") == 0)
continue;
GetFullPathName(cwd, 2048, mask, NULL);
sprintf(mask, "%s\\%s", mask, file.cFileName);
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (!find_file_helper(includepath, origin, includefolder, actualpath, mask))
return 0;
} else {
if (strcmp(filename, file.cFileName) == 0 && matches_includepath(mask, includepath, includefolder)) {
strncpy(actualpath, mask, 2048);
return 0;
}
}
} while (FindNextFile(handle, &file));
FindClose(handle);
#else
FTS *tree;
FTSENT *f;
char *argv[] = { includefolder, NULL };
tree = fts_open(argv, FTS_LOGICAL | FTS_NOSTAT, NULL);
if (tree == NULL)
return 1;
while ((f = fts_read(tree))) {
switch (f->fts_info) {
case FTS_DNR:
case FTS_ERR:
fts_close(tree);
return 2;
case FTS_NS: continue;
case FTS_DP: continue;
case FTS_D: continue;
case FTS_DC: continue;
}
if (strcmp(filename, f->fts_name) == 0 && matches_includepath(f->fts_path, includepath, includefolder)) {
strncpy(actualpath, f->fts_path, 2048);
fts_close(tree);
//.........这里部分代码省略.........
示例4: _tmain
int _tmain(int argc, WCHAR* argv[])
{
printf("PROJECT: Capture-HPC\n");
printf("VERSION: 3.0\n");
printf("DATE: October 19, 2009\n");
printf("COPYRIGHT HOLDER: Victoria University of Wellington, NZ\n");
printf("AUTHORS:\n");
printf("\tChristian Seifert ([email protected])\n");
printf("\tRamon Steenson([email protected])\n");
printf("\tVan Lam Le ([email protected])\n");
printf("\n");
printf("Capture-HPC is free software; you can redistribute it and/or modify\n");
printf("it under the terms of the GNU General Public License, V2 as published by\n");
printf("the Free Software Foundation.\n");
printf("\n");
printf("Capture-HPC is distributed in the hope that it will be useful,\n");
printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
printf("GNU General Public License for more details.\n");
printf("\n");
printf("You should have received a copy of the GNU General Public License\n");
printf("along with Capture-HPC; if not, write to the Free Software\n");
printf("Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,USA\n\n");
/* Set the current directory to the where the CaptureClient.exe is found */
/* This is a bug fix for the VIX library as the runProgramInGuest function
opens the client from within c:\windows\system32 so nothing will load
properly during execution */
wchar_t* szFullPath = new wchar_t[4096];
GetFullPathName(argv[0], 4096, szFullPath, NULL);
std::wstring dir = szFullPath;
dir = dir.substr(0, dir.find_last_of(L"\\")+1);
SetCurrentDirectory(dir.c_str());
GetCurrentDirectory(4096, szFullPath);
LOG(INFO, "Capture: current directroy set - %ls", szFullPath);
/* Delete the log directory */
GetFullPathName(L"logs", 4096, szFullPath, NULL);
SHFILEOPSTRUCT deleteLogDirectory;
deleteLogDirectory.hwnd = NULL;
deleteLogDirectory.pTo = NULL;
deleteLogDirectory.lpszProgressTitle = NULL;
deleteLogDirectory.wFunc = FO_DELETE;
deleteLogDirectory.pFrom = szFullPath;
deleteLogDirectory.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
SHFileOperation(&deleteLogDirectory);
delete [] szFullPath;
//allows to do some custom testing
if(argc>1) {
std::wstring option = argv[1];
if(option == L"-t") {
PluginTest* test = new PluginTest();
test->loadTest();
exit(0);
}
}
std::wstring serverIp = L"";
std::wstring serverPort = L"7070";
std::wstring vmServerId = L"";
std::wstring vmId = L"";
std::wstring logSystemEventsFile = L"";
std::wstring collectModifiedFiles = L"false";
std::wstring captureNetworkPackets = L"false";
for(int i = 1; i < argc; i++)
{
std::wstring option = argv[i];
if(option == L"--help" || option == L"-h") {
printf("\nCapture client is a high interaction client honeypot which using event monitoring can monitor the state of the system it is being run on. ");
printf("Capture can monitor processes, files, and the registry at the moment and classifies an event as being malicious by checking exclusion lists. ");
printf("\nThese exclusion lists are regular expressions which can either allow or deny a particular event from a process in the system. Because of the fact ");
printf("that it uses regular expressions, creating these list can be very simple but can also provide very fine grained exclusion if needed.\nThe client ");
printf("can also copy all modified and deleted files to a temporary directory as well as capture all incoming and outgoing packets on the network adapters ");
printf("on the system.\nThe client can be run in the following two modes:\n");
printf("\n\nClient<->Server\n\n");
printf("The client connects to a central Capture server where the client can be sent urls to visit. These urls can contain other information which tell ");
printf("the client which program to use, for example www.google.com could be visited with either Internet Explorer or Mozilla Firefox and how long to visit the ");
printf("url. While the url is being visited the state of the system is monitored and if anything malicious occurs during the visitation period the event ");
printf("is passed back to the server. In this mode the client is run inside of a virtual machine so that when a malicious event occurs the server can revert ");
printf("the virtual machine to a clean state\n\n");
printf("To use this mode the options -s, -a, -b must be set so the client knows how to connect and authenticate with the server. To configure the ");
printf("programs that are available to visit a url edit the clients.conf file. If -cn are set then the log directory will be sent to the server once ");
printf("a malicious url is visited. For this to work tar.exe and gzip.exe must be included in the Capture Client folder.\n");
printf("\n\nStandalone\n\n");
printf("In this mode the client runs in the background of a system and monitors the state of it. Rather than being controlled by a remote server, in standalone mode ");
printf("the user has control over the system. Malicious events can either be stored in a file or outputted to stdout.");
printf("\n\nUsage: CaptureClient.exe [-chn] [-s server address -a vm server id -b vm id] [-l file]\n");
printf("\n -h\t\tPrint this help message");
printf("\n -s address\tAddress of the server the client connects up to. NOTE -a & -b\n\t\tmust be defined when using this option");
printf("\n -p port\tPort the server user the client connects up to. NOTE -a & -b\n\t\tmust be defined when using this option");
printf("\n -a server id\tUnique id of the virtual machine server that hosts the client");
printf("\n -b vm id\tUnique id of the virtual machine that this client is run on");
printf("\n -l file\tOutput system events to a file rather than stdout\n");
printf("\n -c\t\tCopy files into the log directory when they are modified or\n\t\tdeleted");
printf("\n -n\t\tCapture all incoming and outgoing network packets from the\n\t\tnetwork adapters on the system and store them in .pcap files in\n\t\tthe log directory");
//.........这里部分代码省略.........
示例5: InstallFile
BOOL InstallFile(char *szSource, char *szDestFormat, ...) {
char szDest[MAX_PATH];
char szDestPath[MAX_PATH];
char szDestFile[MAX_PATH];
char *lpszDestFile;
char szCurInst[MAX_PATH];
char szTempFile[MAX_PATH];
DWORD dwFlags = VIFF_DONTDELETEOLD;
DWORD dwRet;
UINT uTmpLen;
char szFailure[256];
va_list val;
va_start(val, szDestFormat);
vsprintf(szDest, szDestFormat, val);
va_end(val);
if (!GetFullPathName(szDest, sizeof szDestPath, szDestPath, &lpszDestFile))
return FALSE;
strcpy(szDestFile, lpszDestFile);
*lpszDestFile=0;
do {
szTempFile[0]=0;
szCurInst[0]=0;
uTmpLen = sizeof szTempFile;
dwRet = VerInstallFile(dwFlags, szSource, szDestFile, g_szProgPath, szDestPath, szCurInst, szTempFile, &uTmpLen);
if (dwRet & VIF_TEMPFILE) {
DeleteFile(szTempFile);
dwRet &= ~VIF_TEMPFILE;
}
szFailure[0]=0;
if (dwRet & (VIF_MISMATCH | VIF_DIFFTYPE))
sprintf(szFailure, "The old %s doesn't look like a VirtualDub file.\n"
"If it belongs to another application, installing the new file may cause "
"the other app to stop functioning.\n"
"Install the new file only if you are sure or have a backup."
,szDestFile);
else if (dwRet & VIF_SRCOLD)
sprintf(szFailure, "%s is older than the %s being installed over.\n"
"You should install the older %s if you do not use other versions "
"of VirtualDub, since the newer file may be incompatible."
,szSource,szDestFile,szSource);
else if (dwRet & VIF_WRITEPROT)
sprintf(szFailure, "The %s being installed over has been marked read-only.\n"
"Override read-only attribute and install anyway?"
,szDestFile);
else if (dwRet & VIF_FILEINUSE)
sprintf(szFailure, "%s is in use. It cannot be installed over right now.\n"
"If you have any copies of VirtualDub or any programs that "
"may be using VirtualDub's AVIFile handler, please close them "
"and then click OK to retry the operation."
,szDestFile);
else if (dwRet & VIF_OUTOFSPACE)
sprintf(szFailure, "Doh! We're out of space trying to write:\n\t%s\n\nCan you clear some up?"
,szDest);
else if (dwRet & VIF_ACCESSVIOLATION)
sprintf(szFailure, "Access violation. Check with your administrator to see if you have "
"the appropriate permissions to write to \"%s\"."
,szDest);
else if (dwRet & VIF_SHARINGVIOLATION)
sprintf(szFailure, "Share violation; something else probably has %s open. Try closing applications that "
"have the file open, and check permissions on network drives."
,szDestFile);
else if (dwRet & VIF_CANNOTCREATE)
sprintf(szFailure, "Couldn't create temporary file %s.\nTry again?", szTempFile);
else if (dwRet & VIF_CANNOTDELETE)
sprintf(szFailure, "Couldn't delete temporary file %s.\nTry installing again?", szTempFile);
else if (dwRet & VIF_CANNOTDELETECUR)
sprintf(szFailure, "Couldn't delete existing file \"%s\".\nTry installing again?", szDest);
else if (dwRet & VIF_CANNOTRENAME)
sprintf(szFailure, "Deleted old file %s, but couldn't move %s into its place.\n"
"You should retry this operation.", szDestFile, szSource);
else if (dwRet & VIF_CANNOTREADSRC)
sprintf(szFailure, "Couldn't read source file \"%s\". Should I try again?"
,szSource);
else if (dwRet & VIF_CANNOTREADDST)
sprintf(szFailure, "Couldn't read destination file \"%s\". I can try installing over it "
"anyway, though."
,szDest);
else if (dwRet & VIF_OUTOFMEMORY)
sprintf(szFailure, "Ran out of memory! Try freeing some up.");
else if (dwRet)
sprintf(szFailure, "Unidentified error copying:\n\t%s\n\t\tto\n\t%s\n\nTry forcing install?"
,szSource
,szDest);
if (szFailure[0])
if (IDNO==MessageBox(NULL, szFailure, "Install error", MB_YESNO | MB_APPLMODAL))
return FALSE;
dwFlags |= VIFF_FORCEINSTALL;
} while(dwRet);
return TRUE;
}
示例6: Bcorrectfilename
int Bcorrectfilename(char *filename, int removefn)
{
#ifdef _WIN32
int r, trailslash=0;
#endif
char path[256]="", fn[64]="", scratch[256], *ptr, *ptr2, ch;
char cwd[256], *cwdp = cwd;
char *tokarr[64];
int ntok=0, i, j;
int grpmode = 0;
if (!Bstrncasecmp(filename,"GRP:",4)) {
grpmode = 1;
for (ptr=filename; *ptr; ptr++) if (*ptr == '\\') *ptr = '/';
}
#ifdef _WIN32
if (!grpmode) {
// Windows uses backslashes so translate all unix-like forwardslashes
for (ptr=filename; *ptr; ptr++) if (*ptr == '/') *ptr = '\\';
if (*(ptr-1) == '\\') trailslash = 1;
r = GetFullPathName(filename, 256, path, &ptr);
if (r > 256) return -1;
if (r == 0) return -1;
if (!trailslash && removefn && ptr) *ptr=0;
if (trailslash) {
if (path[ strlen(path) - 1 ] != '\\')
strcat(path, "\\");
}
for (ptr=path; *ptr; ptr++) if (*ptr == '\\') *ptr = '/';
strcpy(filename,path);
} else {
#endif
#ifndef _WIN32
if (!grpmode) {
Bgetcwd(cwd, 256);
Bstrcat(cwd, "/");
} else {
#endif
cwd[0] = '/';
cwd[1] = 0;
#ifndef _WIN32
}
#endif
ptr2 = filename;
if (grpmode) {
ptr2 += 3;
if (ptr2[1] != '/')
*ptr2 = '/';
else ptr2++;
}
if (removefn) {
ptr = Bstrrchr(ptr2, '/');
if (ptr) ptr[1] = 0;
else if (!grpmode) ptr2[0] = 0;
}
// now we have all the bits and pieces, clean it all up
scratch[0] = 0;
if (ptr2[0] != '/') {
// relative path, which means prepend the current dir to the path
Bstrcat(scratch, cwdp);
}
Bstrcat(scratch, ptr2);
ptr2 = scratch;
while ((ptr = Bstrtoken(ptr2==scratch?scratch:NULL,"/",&ptr2,1)) != NULL) {
if (!Bstrcmp(ptr,".")) continue;
else if (!Bstrcmp(ptr,"..")) {
if (ntok>0) ntok--;
} else {
tokarr[ntok++] = ptr;
}
}
ptr2 = filename;
if (grpmode) {
Bstrcpy(filename,"GRP:");
ptr2 += 4;
} else filename[0] = 0;
*(ptr2++) = '/';
for (i=0; i<ntok; i++) {
ptr = tokarr[i];
if (i>0) *(ptr2++) = '/';
while (*ptr) *(ptr2++) = *(ptr++);
}
if (removefn) if (*(ptr2-1) != '/') *(ptr2++) = '/';
*(ptr2) = 0;
#ifdef _WIN32
}
#endif
//.........这里部分代码省略.........
示例7: WinMain
//.........这里部分代码省略.........
}
// perform trust check
itvEnum itv = IsPackageTrusted(szModuleFile, szMsiCacheFile, DownloadUI.GetCurrentWindow());
if (itvWintrustNotOnMachine == itv)
{
PostError(hInst, DownloadUI.GetCurrentWindow(), szAppTitle, IDS_NO_WINTRUST);
uiRet = ERROR_CALL_NOT_IMPLEMENTED;
goto CleanUp;
}
else if (itvUnTrusted == itv)
{
PostFormattedError(hInst, DownloadUI.GetCurrentWindow(), szAppTitle, IDS_UNTRUSTED, szInstallPath);
uiRet = HRESULT_CODE(TRUST_E_SUBJECT_NOT_TRUSTED);
goto CleanUp;
}
}
else
{
// lack of BASEURL property indicates assumption of Media source
// generate the path to the Msi file = szModuleFile + msiFile
// note: msiFile is a relative path
cchTempPath = lstrlen(szModuleFile) + lstrlen(szMsiFile) + 2; // 1 for null terminator, 1 for back slash
szTempPath = new char[cchTempPath];
if (!szTempPath)
{
ReportErrorOutOfMemory(hInst, DownloadUI.GetCurrentWindow(), szAppTitle);
uiRet = ERROR_OUTOFMEMORY;
goto CleanUp;
}
// find 'setup.exe' in the path so we can remove it
if (0 == GetFullPathName(szModuleFile, cchTempPath, szTempPath, &szFilePart))
{
uiRet = GetLastError();
PostFormattedError(hInst, DownloadUI.GetCurrentWindow(), szAppTitle, IDS_INVALID_PATH, szTempPath);
goto CleanUp;
}
if (szFilePart)
*szFilePart = '\0';
if (FAILED(StringCchCat(szTempPath, cchTempPath, szMsiFile)))
{
PostError(hInst, DownloadUI.GetCurrentWindow(), szAppTitle, IDS_INTERNAL_ERROR);
uiRet = ERROR_INSTALL_FAILURE;
goto CleanUp;
}
cchInstallPath = 2*cchTempPath;
szInstallPath = new char[cchInstallPath];
if (!szInstallPath)
{
ReportErrorOutOfMemory(hInst, DownloadUI.GetCurrentWindow(), szAppTitle);
uiRet = ERROR_OUTOFMEMORY;
goto CleanUp;
}
// normalize the path
cchReturn = GetFullPathName(szTempPath, cchInstallPath, szInstallPath, &szFilePart);
if (cchReturn > cchInstallPath)
{
// try again, with larger buffer
delete [] szInstallPath;
cchInstallPath = cchReturn;
szInstallPath = new char[cchInstallPath];
示例8: lrealpath
char *
lrealpath (const char *filename)
{
/* Method 1: The system has a compile time upper bound on a filename
path. Use that and realpath() to canonicalize the name. This is
the most common case. Note that, if there isn't a compile time
upper bound, you want to avoid realpath() at all costs. */
#if defined(REALPATH_LIMIT)
{
char buf[REALPATH_LIMIT];
const char *rp = realpath (filename, buf);
if (rp == NULL)
rp = filename;
return strdup (rp);
}
#endif /* REALPATH_LIMIT */
/* Method 2: The host system (i.e., GNU) has the function
canonicalize_file_name() which malloc's a chunk of memory and
returns that, use that. */
#if defined(HAVE_CANONICALIZE_FILE_NAME)
{
char *rp = canonicalize_file_name (filename);
if (rp == NULL)
return strdup (filename);
else
return rp;
}
#endif
/* Method 3: Now we're getting desperate! The system doesn't have a
compile time buffer size and no alternative function. Query the
OS, using pathconf(), for the buffer limit. Care is needed
though, some systems do not limit PATH_MAX (return -1 for
pathconf()) making it impossible to pass a correctly sized buffer
to realpath() (it could always overflow). On those systems, we
skip this. */
#if defined (HAVE_REALPATH) && defined (HAVE_UNISTD_H)
{
/* Find out the max path size. */
long path_max = pathconf ("/", _PC_PATH_MAX);
if (path_max > 0)
{
/* PATH_MAX is bounded. */
char *buf, *rp, *ret;
buf = (char *) malloc (path_max);
if (buf == NULL)
return NULL;
rp = realpath (filename, buf);
ret = strdup (rp ? rp : filename);
free (buf);
return ret;
}
}
#endif
/* The MS Windows method. If we don't have realpath, we assume we
don't have symlinks and just canonicalize to a Windows absolute
path. GetFullPath converts ../ and ./ in relative paths to
absolute paths, filling in current drive if one is not given
or using the current directory of a specified drive (eg, "E:foo").
It also converts all forward slashes to back slashes. */
#if defined (_WIN32)
{
char buf[MAX_PATH];
char* basename;
DWORD len = GetFullPathName (filename, MAX_PATH, buf, &basename);
if (len == 0 || len > MAX_PATH - 1)
return strdup (filename);
else
{
/* The file system is case-preserving but case-insensitive,
Canonicalize to lowercase, using the codepage associated
with the process locale. */
CharLowerBuff (buf, len);
return strdup (buf);
}
}
#endif
/* This system is a lost cause, just duplicate the filename. */
return strdup (filename);
}
示例9: CreateShortcut
static BOOL
CreateShortcut(
LPCTSTR pszFolder,
LPCTSTR pszName,
LPCTSTR pszCommand,
LPCTSTR pszDescription,
INT iIconNr)
{
TCHAR szPath[MAX_PATH];
TCHAR szExeName[MAX_PATH];
LPTSTR Ptr;
TCHAR szWorkingDirBuf[MAX_PATH];
LPTSTR pszWorkingDir = NULL;
LPTSTR lpFilePart;
DWORD dwLen;
if (ExpandEnvironmentStrings(pszCommand,
szPath,
sizeof(szPath) / sizeof(szPath[0])) == 0)
{
_tcscpy(szPath, pszCommand);
}
if ((_taccess(szPath, 0 )) == -1)
/* Expected error, don't return FALSE */
return TRUE;
dwLen = GetFullPathName(szPath,
sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0]),
szWorkingDirBuf,
&lpFilePart);
if (dwLen != 0 && dwLen <= sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0]))
{
/* Since those should only be called with (.exe) files,
lpFilePart has not to be NULL */
ASSERT(lpFilePart != NULL);
/* Save the file name */
_tcscpy(szExeName, lpFilePart);
/* We're only interested in the path. Cut the file name off.
Also remove the trailing backslash unless the working directory
is only going to be a drive, ie. C:\ */
*(lpFilePart--) = _T('\0');
if (!(lpFilePart - szWorkingDirBuf == 2 && szWorkingDirBuf[1] == _T(':') &&
szWorkingDirBuf[2] == _T('\\')))
{
*lpFilePart = _T('\0');
}
pszWorkingDir = szWorkingDirBuf;
}
_tcscpy(szPath, pszFolder);
Ptr = PathAddBackslash(szPath);
_tcscpy(Ptr, pszName);
// FIXME: we should pass 'command' straight in here, but shell32 doesn't expand it
return SUCCEEDED(CreateShellLink(szPath, szExeName, _T(""), pszWorkingDir, szExeName, iIconNr, pszDescription));
}
示例10: CommandAttrib
//.........这里部分代码省略.........
break;
case _T('H'):
dwMask |= FILE_ATTRIBUTE_HIDDEN;
dwAttrib |= FILE_ATTRIBUTE_HIDDEN;
break;
case _T('R'):
dwMask |= FILE_ATTRIBUTE_READONLY;
dwAttrib |= FILE_ATTRIBUTE_READONLY;
break;
case _T('S'):
dwMask |= FILE_ATTRIBUTE_SYSTEM;
dwAttrib |= FILE_ATTRIBUTE_SYSTEM;
break;
default:
error_invalid_parameter_format (arg[i]);
freep (arg);
return -1;
}
}
else if (*arg[i] == _T('-'))
{
if (_tcslen (arg[i]) != 2)
{
error_invalid_parameter_format (arg[i]);
freep (arg);
return -1;
}
switch ((TCHAR)_totupper (arg[i][1]))
{
case _T('A'):
dwMask |= FILE_ATTRIBUTE_ARCHIVE;
dwAttrib &= ~FILE_ATTRIBUTE_ARCHIVE;
break;
case _T('H'):
dwMask |= FILE_ATTRIBUTE_HIDDEN;
dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN;
break;
case _T('R'):
dwMask |= FILE_ATTRIBUTE_READONLY;
dwAttrib &= ~FILE_ATTRIBUTE_READONLY;
break;
case _T('S'):
dwMask |= FILE_ATTRIBUTE_SYSTEM;
dwAttrib &= ~FILE_ATTRIBUTE_SYSTEM;
break;
default:
error_invalid_parameter_format (arg[i]);
freep (arg);
return -1;
}
}
}
if (argc == 0)
{
DWORD len;
len = GetCurrentDirectory (MAX_PATH, szPath);
if (szPath[len-1] != _T('\\'))
{
szPath[len] = _T('\\');
szPath[len + 1] = 0;
}
_tcscpy (szFileName, _T("*.*"));
PrintAttribute (szPath, szFileName, bRecurse);
freep (arg);
return 0;
}
/* get full file name */
for (i = 0; i < argc; i++)
{
if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/')))
{
LPTSTR p;
GetFullPathName (arg[i], MAX_PATH, szPath, NULL);
p = _tcsrchr (szPath, _T('\\')) + 1;
_tcscpy (szFileName, p);
*p = _T('\0');
if (dwMask == 0)
PrintAttribute (szPath, szFileName, bRecurse);
else
ChangeAttribute (szPath, szFileName, dwMask,
dwAttrib, bRecurse, bDirectories);
}
}
freep (arg);
return 0;
}
示例11: InitMaps
void InitMaps()
{
hash_map<wstring,WORD> slots;
// process boots map file
hash_map<DWORD,wstring> mapFile;
wstring mpath(getPesInfo()->gdbDir);
mpath += L"GDB\\boots\\map.txt";
if (!readMap(mpath.c_str(), mapFile))
{
LOG1S(L"Couldn't open boots map for reading: {%s}",mpath.c_str());
}
else
{
int slot = 0;
for (hash_map<DWORD,wstring>::iterator it = mapFile.begin(); it != mapFile.end(); it++)
{
wstring boot(it->second);
string_strip(boot);
if (!boot.empty())
string_strip_quotes(boot);
if (!boot.empty())
{
// check that the file exists, so that we don't crash
// later, when it's attempted to replace a boot.
wstring filename(getPesInfo()->gdbDir);
filename += L"GDB\\boots\\" + boot;
HANDLE handle;
DWORD size;
if (OpenFileIfExists(filename.c_str(), handle, size))
{
CloseHandle(handle);
if (slot >= MAX_BOOTS)
{
LOG2N(L"ERROR in bootserver map: Too many boots: %d (MAX supported = %d). Aborting map processing", slot, MAX_BOOTS);
break;
}
hash_map<wstring,WORD>::iterator wit = slots.find(boot);
if (wit != slots.end())
{
// boot already has an assigned slot
_boot_slots.insert(pair<DWORD,WORD>(
it->first, wit->second));
}
else
{
_boot_slots.insert(pair<DWORD,WORD>(
it->first, FIRST_EXTRA_BOOT_SLOT + slot));
slots.insert(pair<wstring,WORD>(
boot, FIRST_EXTRA_BOOT_SLOT + slot));
slot++;
}
}
else
LOG1N1S(L"ERROR in bootserver map for ID = %d: FAILED to open boot BIN \"%s\". Skipping", it->first, boot.c_str());
}
}
}
if (_bootserv_config._random_boots)
{
// enumerate all boots and add them to the slots list
wstring dir(getPesInfo()->gdbDir);
dir += L"GDB\\boots\\";
// normalize the path
wchar_t fullpath[MAX_PATH];
GetFullPathName(dir.c_str(), MAX_PATH, fullpath, 0);
dir = fullpath;
int count;
LOG(L"Enumerating all boots in GDB...");
EnumerateBoots(dir, count);
_num_random_boots = count;
LOG1N(L"_num_random_boots = %d", _num_random_boots);
}
// initialize fast bin lookup table
for (hash_map<wstring,WORD>::iterator sit = slots.begin();
sit != slots.end();
sit++)
{
_fast_bin_table[sit->second - FIRST_EXTRA_BOOT_SLOT] =
new wstring(sit->first);
if (k_bootserv.debug)
LOG1N1S(L"slot %d <-- boot {%s}", sit->second, sit->first.c_str());
}
LOG1N(L"Total assigned GDB boots: %d", slots.size());
LOG1N(L"Total random GDB boots: %d", _num_random_boots);
if (slots.size() > 0)
_num_slots = FIRST_EXTRA_BOOT_SLOT + slots.size();
if (_num_random_boots > 0)
_num_slots = FIRST_RANDOM_BOOT_SLOT + _num_random_boots;
LOG1N(L"_num_slots = %d", _num_slots);
}
示例12: RemoveDisk
ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary)
{
FloppyDrive* pDrive = &m_floppyDrive[drive];
FloppyDisk* pFloppy = &pDrive->m_disk;
if (pFloppy->m_imagehandle)
RemoveDisk(drive);
// Reset the disk's attributes, but preserve the drive's attributes (GH#138/Platoon, GH#640)
// . Changing the disk (in the drive) doesn't affect the drive's attributes.
pFloppy->clear();
const DWORD dwAttributes = GetFileAttributes(pszImageFilename);
if(dwAttributes == INVALID_FILE_ATTRIBUTES)
pFloppy->m_bWriteProtected = false; // Assume this is a new file to create
else
pFloppy->m_bWriteProtected = bForceWriteProtected ? true : (dwAttributes & FILE_ATTRIBUTE_READONLY);
// Check if image is being used by the other drive, and if so remove it in order so it can be swapped
{
const char* pszOtherPathname = DiskGetFullPathName(!drive);
char szCurrentPathname[MAX_PATH];
DWORD uNameLen = GetFullPathName(pszImageFilename, MAX_PATH, szCurrentPathname, NULL);
if (uNameLen == 0 || uNameLen >= MAX_PATH)
strcpy_s(szCurrentPathname, MAX_PATH, pszImageFilename);
if (!strcmp(pszOtherPathname, szCurrentPathname))
{
EjectDisk(!drive);
FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES);
}
}
ImageError_e Error = ImageOpen(pszImageFilename,
&pFloppy->m_imagehandle,
&pFloppy->m_bWriteProtected,
bCreateIfNecessary,
pFloppy->m_strFilenameInZip);
if (Error == eIMAGE_ERROR_NONE && ImageIsMultiFileZip(pFloppy->m_imagehandle))
{
TCHAR szText[100+MAX_PATH];
szText[sizeof(szText)-1] = 0;
_snprintf(szText, sizeof(szText)-1, "Only the first file in a multi-file zip is supported\nUse disk image '%s' ?", pFloppy->m_strFilenameInZip.c_str());
int nRes = MessageBox(g_hFrameWindow, szText, TEXT("Multi-Zip Warning"), MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND);
if (nRes == IDNO)
{
RemoveDisk(drive);
Error = eIMAGE_ERROR_REJECTED_MULTI_ZIP;
}
}
if (Error == eIMAGE_ERROR_NONE)
{
GetImageTitle(pszImageFilename, pFloppy->m_imagename, pFloppy->m_fullname);
Video_ResetScreenshotCounter(pFloppy->m_imagename);
}
else
{
Video_ResetScreenshotCounter(NULL);
}
SaveLastDiskImage(drive);
return Error;
}
示例13: main
int _CRTAPI1 main (int c, char *v[])
{
int tenth, pct;
int bValidBuf;
DWORDLONG tmpTot, tmpFree;
DWORD cSecsPerClus, cBytesPerSec, cFreeClus, cTotalClus;
USESTAT useTot, useTmp;
char Buffer[MAX_PATH];
char *p;
SHIFT (c, v);
while (c && (**v == '/' || **v == '-'))
{
if (!strcmp (*v + 1, "s"))
fNodeSummary = TRUE;
else
{
puts ("Usage: DU [/s] [dirs]");
exit (1);
}
SHIFT (c, v);
}
if (c == 0)
{
GetCurrentDirectory( MAX_PATH, (LPSTR)buf );
root[0] = buf[0];
if( bValidDrive = GetDiskFreeSpace( root,
&cSecsPerClus,
&cBytesPerSec,
&cFreeClus,
&cTotalClus ) == TRUE )
{
bytesPerAlloc = cBytesPerSec * cSecsPerClus;
totFree = (DWORDLONG)bytesPerAlloc * cFreeClus;
totDisk = (DWORDLONG)bytesPerAlloc * cTotalClus;
}
useTot = DoDu (buf);
if (fNodeSummary)
TotPrint (&useTot, buf);
}
else
{
CLEARUSE (useTot);
while (c)
{
LPSTR FilePart;
bValidBuf = GetFullPathName( *v, MAX_PATH, buf, &FilePart);
if ( bValidBuf )
{
if ( buf[0] == '\\' ) {
fUnc = TRUE;
bValidDrive = TRUE;
bytesPerAlloc = 1;
} else {
root[0] = buf[0];
if( bValidDrive = GetDiskFreeSpace( root,
&cSecsPerClus,
&cBytesPerSec,
&cFreeClus,
&cTotalClus ) == TRUE)
{
bytesPerAlloc = cBytesPerSec * cSecsPerClus;
totFree = (DWORDLONG)bytesPerAlloc * cFreeClus;
totDisk = (DWORDLONG)bytesPerAlloc * cTotalClus;
} else
printf ("Invalid drive or directory %s\n", *v );
}
if( bValidDrive & (GetFileAttributes( buf ) & FILE_ATTRIBUTE_DIRECTORY ) != 0 )
{
useTmp = DoDu (buf);
if (fNodeSummary)
TotPrint (&useTmp, buf);
ADDUSE (useTot, useTmp);
}
}
else
printf ("Invalid drive or directory %s\n", *v );
SHIFT (c, v);
}
}
if (cDisp != 0)
{
if (cDisp > 1)
TotPrint (&useTot, "Total");
/* quick full-disk test */
if ( !fUnc ) {
if (totFree == 0)
puts ("Disk is full");
else
{
//.........这里部分代码省略.........
示例14: ProcessDirectory
static DWORD
ProcessDirectory(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
{
TCHAR szFullPath[MAX_PATH];
LPTSTR pFilePart;
LPTSTR pSearchPart;
HANDLE hFile;
WIN32_FIND_DATA f;
DWORD dwFiles = 0;
GetFullPathName (FileName,
MAX_PATH,
szFullPath,
&pFilePart);
dwFiles = DeleteFiles(szFullPath, dwFlags, dwAttrFlags);
if (dwFiles & 0x80000000)
return dwFiles;
if (*dwFlags & DEL_SUBDIR)
{
/* Get just the file name */
pSearchPart = _tcsrchr(FileName,_T('\\'));
if(pSearchPart != NULL)
pSearchPart++;
else
pSearchPart = FileName;
/* Get the full path to the file */
GetFullPathName (FileName,MAX_PATH,szFullPath,NULL);
/* strip the filename off of it */
pFilePart = _tcsrchr(szFullPath, _T('\\'));
if (pFilePart == NULL)
{
pFilePart = szFullPath;
}
else
{
pFilePart++;
}
_tcscpy(pFilePart, _T("*"));
hFile = FindFirstFile(szFullPath, &f);
if (hFile != INVALID_HANDLE_VALUE)
{
do
{
if (!(f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
!_tcscmp(f.cFileName, _T(".")) ||
!_tcscmp(f.cFileName, _T("..")))
continue;
_tcscpy(pFilePart, f.cFileName);
_tcscat(pFilePart, _T("\\"));
_tcscat(pFilePart, pSearchPart);
dwFiles +=ProcessDirectory(szFullPath, dwFlags, dwAttrFlags);
if (dwFiles & 0x80000000)
{
break;
}
}
while (FindNextFile (hFile, &f));
FindClose (hFile);
}
}
return dwFiles;
}
示例15: _tmain
int __cdecl
_tmain(
int argc,
TCHAR* argv[]
)
{
TCHAR DestPath[MAX_PATH];
ULONG Size = MAX_PATH;
TCHAR * InfPath = NULL;
TCHAR DriverPackageInfPath[MAX_PATH];
DWORD Ret;
TCHAR Option;
BOOL NeedRebootDev = FALSE;
BOOL NeedRebootDrvPkg = FALSE;
DWORD Flags = 0;
LPTSTR lpFilePart;
int i;
DWORD dw;
Size = MAX_PATH;
_tprintf( TEXT("Driver Installer Sample Program\n") );
if( argc < 3 )
{
_tprintf( TEXT("USAGE: drvinst /i /c /r /g <inf-filename> [Flag(s)]\n") );
_tprintf( TEXT("\nOptions:\n"));
_tprintf( TEXT("/i : re-install driver package and devices if presented.\n") );
_tprintf( TEXT("/u : uninstall devices and driver package.\n") );
_tprintf( TEXT("/g : get installed driver package path.\n") );
_tprintf( TEXT("\n<inf-filename> : path to the inf file.\n") );
_tprintf( TEXT("\nFlags:\n"));
_tprintf( TEXT("DRIVER_PACKAGE_REPAIR: 0x00000001 ( 1)\n"));
_tprintf( TEXT("DRIVER_PACKAGE_SILENT: 0x00000002 ( 2)\n"));
_tprintf( TEXT("DRIVER_PACKAGE_FORCE: 0x00000004 ( 4)\n"));
_tprintf( TEXT("DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT: 0x00000008 ( 8)\n"));
_tprintf( TEXT("DRIVER_PACKAGE_LEGACY: 0x00000010 (16)\n"));
_tprintf( TEXT("DRIVER_PACKAGE_DELETE_FILES: 0x00000020 (32)\n"));
return 0;
}
//
// Get command line choices
//
//
// The code suppresses the warning 28193 for the call to _totlower.
// This suppression is done because that function has a check return
// annotation on it. However, it doesn't return an error code
// and the check return annotation is really being used to indicate
// that the return value of the function should be looked at and/or
// assigned to a variable. The check return annotation means the return
// value should always be checked in all code paths. The return value is
// assigned to a variable, but the return in the for loop could cause
// this function to exit before Option is ever examined. For that case,
// the code doesn't need to check the value of Option so the warning
// is being suppressed
//
#pragma warning( suppress: 28193)
Option = (TCHAR)_totlower(argv[1][1]);
InfPath = argv[2];
for ( i = 3; i<argc; i++ ){
dw = _ttol( argv[i] );
//
// Either an error occurred during conversion of a flags parameter
// into a long or a flag of 0 was specified. Either way,
// this is invalid input.
//
if (0 == dw)
{
_tprintf( TEXT("An invalid flag was specified.") );
return 0;
}
Flags |= dw;
}
GetFullPathName( InfPath, MAX_PATH, DriverPackageInfPath, &lpFilePart);
_tprintf( TEXT("INFO: Option \"/%c\"\n"), Option );
_tprintf( TEXT("INFO: Input file \"%s\"\n"), DriverPackageInfPath );
_tprintf( TEXT("INFO: Flags 0x%X (%u)\n\n"), Flags, Flags );
DIFXAPISetLogCallback( LogCallback, (PVOID)NULL );
Ret = ERROR_SUCCESS;
if ( TEXT('u') == Option )
{
_tprintf( TEXT("INFO: uninstalling devices.\n"));
if ( TRUE == RemoveDevices( &NeedRebootDev ) ) {
_tprintf( TEXT("SUCCESS: uninstalled devices.\n") );
}
else {
//.........这里部分代码省略.........