本文整理匯總了C++中DeleteFile函數的典型用法代碼示例。如果您正苦於以下問題:C++ DeleteFile函數的具體用法?C++ DeleteFile怎麽用?C++ DeleteFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DeleteFile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: deleteFile
bool deleteFile(const char* path) {
return DeleteFile(path)!=0;
}
示例2: updateAll
//.........這裏部分代碼省略.........
/* sync the file/folder over, then add the file metadata to the data file and runtime maps */
if ( MAIN_APP->getAttr()[i].objtype == OrangeFS_TYPE_DIRECTORY )
{
MAIN_APP->syncDir(metadataHandler->getRemoteFileName(i));
}
else
{
MAIN_APP->syncFile(metadataHandler->getRemoteFileName(i), MAIN_APP->getAttr()[i].size);
}
metadataHandler->addFileMetadata(metadataHandler->getRemoteFileName(i), &MAIN_APP->getAttr()[i]);
syncList->updateList(metadataHandler->getRemoteFileName(i));
}
}
}
deleteIndexes.reserve(MAIN_APP->getNumFiles()); /* if all the files on the server were deleted, getNumFiles() would appropriately hold index for all of them */
if (filesDeleted)
{
for (int i=0; i < MAIN_APP->getNumFiles(); i++)
{
/* the local file wasn't found on the server, delete locally */
if ( !metadataHandler->isLocalOnServer( metadataHandler->getFileName(i) ) )
{
/* THIS ISN"T WORKING, GETS IN HERE EVERY TIME */
orangefs_debug_print("---- ADDDED index : %d\n", i);
deleteIndexes.push_back(i);
}
}
orangefs_debug_print("NUM FILES FOR DELETE : %d\n", deleteIndexes.size());
/* now we have the indexes of files stored locally to be deleted */
for (int i=0; i < deleteIndexes.size(); i++)
{
/***********************************************************************************************/
/* we will need to delete the actual file, and all of it's traces at the following locations : */
/* */
/* 1) the physical file on the local hard disk */
/* 2) the metadata entry from the metadata file */
/* 3) the list control entry for the file */
/* 4) the runtime maps */
/***********************************************************************************************/
/* (1) */
wxString fullPath = MAIN_APP->getLocalSyncPath();
fullPath += metadataHandler->getFileName(i);
#ifdef WIN32
DeleteFile(fullPath.c_str());
#elif
remove(fullPath.c_str());
#endif
/* (2) and (4) */
metadataHandler->removeFile(metadataHandler->getFileName(i));
/* (3) */
MAIN_FRAME->fileHandler->removeListData(metadataHandler->getFileName(i));
}
}
#ifdef WIN32
Sleep(5000); /* Wait 5 seconds before checking for updates again */
#elif
sleep(5000); /* maybe in the future have the user set this value in the app configuration */
#endif
stringstream ss;
ss << timesUpdated;
/* clear and refresh the status text */
statusBarString.clear();
statusBarString = "Updated ";
statusBarString += ss.str();
statusBarString += " times";
MAIN_FRAME->setStatusbarText(statusBarString);
timesUpdated++;
}while(!MAIN_APP->stillUpdating()); /* keep checking for new files or existing file modifications on the subscribed dirs/files */
done_syncing:
/* let the app know we're finished syncing */
MAIN_APP->finishedSyncing(true);
orangefs_debug_print("---- Syncing Completed ----\n");
for (int i=0; i < MAX_FILES; i++)
{
free(mainFileListing[i]);
}
free(mainFileListing);
deleteIndexes.clear();
LPDWORD exitCode;
GetExitCodeThread(dirWatcher->getThreadHandle(), exitCode);
TerminateThread(dirWatcher->getThreadHandle(), *exitCode);
return ret;
}
示例3: InUn
static BOOL
InUn(int remove, char *drivername, char *dllname, char *dll2name, char *dsname)
{
char path[301], driver[300], attr[300], inst[400], inst2[400];
WORD pathmax = sizeof (path) - 1, pathlen;
DWORD usecnt, mincnt;
if (SQLInstallDriverManager(path, pathmax, &pathlen)) {
char *p;
sprintf(driver, "%s;Driver=%s;Setup=%s;",
drivername, dllname, dllname);
p = driver;
while (*p) {
if (*p == ';') {
*p = '\0';
}
++p;
}
usecnt = 0;
SQLInstallDriverEx(driver, NULL, path, pathmax, &pathlen,
ODBC_INSTALL_INQUIRY, &usecnt);
sprintf(driver, "%s;Driver=%s\\%s;Setup=%s\\%s;",
drivername, path, dllname, path, dllname);
p = driver;
while (*p) {
if (*p == ';') {
*p = '\0';
}
++p;
}
sprintf(inst, "%s\\%s", path, dllname);
if (dll2name) {
sprintf(inst2, "%s\\%s", path, dll2name);
}
if (!remove && usecnt > 0) {
/* first install try: copy over driver dll, keeping DSNs */
if (GetFileAttributes(dllname) != INVALID_FILE_ATTRIBUTES &&
CopyFile(dllname, inst, 0) &&
CopyOrDelModules(dllname, path, 0)) {
if (dll2name != NULL) {
CopyFile(dll2name, inst2, 0);
}
return TRUE;
}
}
mincnt = remove ? 1 : 0;
while (usecnt != mincnt) {
if (!SQLRemoveDriver(driver, TRUE, &usecnt)) {
break;
}
}
if (remove) {
if (!SQLRemoveDriver(driver, TRUE, &usecnt)) {
ProcessErrorMessages("SQLRemoveDriver");
return FALSE;
}
if (!usecnt) {
char buf[512];
DeleteFile(inst);
/* but keep inst2 */
CopyOrDelModules(dllname, path, 1);
if (!quiet) {
sprintf(buf, "%s uninstalled.", drivername);
MessageBox(NULL, buf, "Info",
MB_ICONINFORMATION|MB_OK|MB_TASKMODAL|
MB_SETFOREGROUND);
}
}
if (nosys) {
goto done;
}
sprintf(attr, "DSN=%s;", dsname);
p = attr;
while (*p) {
if (*p == ';') {
*p = '\0';
}
++p;
}
SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, drivername, attr);
goto done;
}
if (GetFileAttributes(dllname) == INVALID_FILE_ATTRIBUTES) {
return FALSE;
}
if (!CopyFile(dllname, inst, 0)) {
char buf[512];
sprintf(buf, "Copy %s to %s failed", dllname, inst);
MessageBox(NULL, buf, "CopyFile",
MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
return FALSE;
}
if (dll2name != NULL && !CopyFile(dll2name, inst2, 0)) {
char buf[512];
sprintf(buf, "Copy %s to %s failed", dll2name, inst2);
MessageBox(NULL, buf, "CopyFile",
//.........這裏部分代碼省略.........
示例4: MPQInit
Application::Application(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MPQInit();
instance = this;
resources = NULL;
imageLibrary = NULL;
dotaLibrary = NULL;
mainWindow = NULL;
cache = NULL;
hInstance = _hInstance;
_loaded = false;
root = String::getPath(getAppPath());
cfg.read();
warLoader = new MPQLoader("Custom_V1");
warLoader->loadArchive(String::buildFullName(cfg.warPath, "war3.mpq"));
warLoader->loadArchive(String::buildFullName(cfg.warPath, "war3x.mpq"));
warLoader->loadArchive(String::buildFullName(cfg.warPath, "war3xlocal.mpq"));
warLoader->loadArchive(String::buildFullName(cfg.warPath, "war3patch.mpq"));
if (logCommand(lpCmdLine))
return;
ScriptType::initTypes();
UpdateDialog::init(hInstance);
INITCOMMONCONTROLSEX iccex;
iccex.dwSize = sizeof iccex;
iccex.dwICC = ICC_STANDARD_CLASSES | ICC_PROGRESS_CLASS |
ICC_BAR_CLASSES | ICC_TREEVIEW_CLASSES | ICC_LISTVIEW_CLASSES |
ICC_TAB_CLASSES | ICC_UPDOWN_CLASS | ICC_DATE_CLASSES;
InitCommonControlsEx(&iccex);
LoadLibrary("Riched20.dll");
OleInitialize(NULL);
String path = String::getPath(getAppPath());
String resPath = String::buildFullName(path, "resources.mpq");
String patchPath = String::buildFullName(path, "install.mpq");
File* tOpen = File::open(resPath, File::READ);
if (tOpen == NULL)
{
tOpen = File::open(patchPath, File::READ);
if (tOpen)
{
delete tOpen;
MoveFile(patchPath, resPath);
}
}
else
delete tOpen;
resources = MPQArchive::open(resPath);
MPQArchive* patch = MPQArchive::open(patchPath, File::READ);
if (patch)
{
for (uint32 i = 0; i < patch->getHashSize(); i++)
{
char const* name = patch->getFileName(i);
if (name)
{
MPQFile* source = patch->openFile(i, File::READ);
if (source)
{
MPQFile* dest = resources->openFile(name, File::REWRITE);
if (dest)
{
static uint8 buf[1024];
while (int length = source->read(buf, sizeof buf))
dest->write(buf, length);
delete dest;
}
delete source;
}
}
}
delete patch;
DeleteFile(patchPath);
}
imageLibrary = new ImageLibrary(resources);
cache = new CacheManager();
dotaLibrary = new DotaLibrary();
#if 0
File* dlog = File::open("diff.txt", File::REWRITE);
for (int pt = 0; pt < 120; pt++)
{
String prev = "";
bool different = false;
for (int ver = 1; ver <= 80 && !different; ver++)
{
Dota* dota = dotaLibrary->getDota(makeVersion(6, ver));
if (dota)
{
Dota::Hero* hero = dota->getHero(pt);
if (hero)
{
if (prev == "")
prev = hero->name;
//.........這裏部分代碼省略.........
示例5: RecurseDeletePath
bool RecurseDeletePath(const char * a_path)
{
WIN32_FIND_DATA findData;
char path[MAX_PATH] = "";
strcpy(path,a_path);
// remove trailing '\' char
int last = (int)strlen(path) - 1;
if(path[last] == '\\')
{
path[last] = '\0';
}
// is path valid
HANDLE h = FindFirstFile(path,&findData);
// path not could not be found OR path is a file, not a folder
if((h == INVALID_HANDLE_VALUE) || (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)))
{
return false;
}
FindClose(h);
h = NULL;
// push current working directory
char currDir[MAX_PATH + 1] = "";
GetCurrentDirectory(MAX_PATH,currDir);
SetCurrentDirectory(path);
// iterate over contents of folder
h = FindFirstFile("*",&findData);
if(h != INVALID_HANDLE_VALUE)
{
for(;;)
{
if(strcmp(findData.cFileName,".") != 0 && strcmp(findData.cFileName,"..") != 0)
{
if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
RecurseDeletePath(findData.cFileName);
}
else
{
DWORD attrs = GetFileAttributes(findData.cFileName);
if(attrs & FILE_ATTRIBUTE_READONLY)
{
SetFileAttributes(findData.cFileName,attrs ^ FILE_ATTRIBUTE_READONLY);
}
if(DeleteFile(findData.cFileName) != TRUE)
{
DWORD res = GetLastError();
printf("\nDeleteFile() returned '%d'..\n",(int)res);
}
}
}
if(!FindNextFile(h,&findData)) break;
}
}
// pop current working directory
SetCurrentDirectory(currDir);
FindClose(h);
h = NULL;
// remove this directory
DWORD attrs = GetFileAttributes(path);
if(attrs & FILE_ATTRIBUTE_READONLY)
{
SetFileAttributes(path,attrs ^ FILE_ATTRIBUTE_READONLY);
}
return RemoveDirectory(path) != 0;
}
示例6: DeleteFile
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
DeleteFile("sprites\\fbDefines.fabric");
}
示例7: DeleteLogFiles
int DeleteLogFiles()
{
WIN32_FIND_DATA ffd;
char szDir[MAX_PATH];
char File[MAX_PATH];
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError=0;
LARGE_INTEGER ft;
time_t now = time(NULL);
int Age;
// Prepare string for use with FindFile functions. First, copy the
// string to a buffer, then append '\*' to the directory name.
strcpy(szDir, GetBPQDirectory());
strcat(szDir, "\\logs\\Log_*.txt");
// Find the first file in the directory.
hFind = FindFirstFile(szDir, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
return dwError;
}
// List all the files in the directory with some info about them.
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
OutputDebugString(ffd.cFileName);
}
else
{
ft.HighPart = ffd.ftCreationTime.dwHighDateTime;
ft.LowPart = ffd.ftCreationTime.dwLowDateTime;
ft.QuadPart -= 116444736000000000;
ft.QuadPart /= 10000000;
Age = (now - ft.LowPart) / 86400;
if (Age > LogAge)
{
sprintf(File, "%s/logs/%s%c", GetBPQDirectory(), ffd.cFileName, 0);
if (DeletetoRecycleBin)
DeletetoRecycle(File);
else
DeleteFile(File);
}
}
}
while (FindNextFile(hFind, &ffd) != 0);
dwError = GetLastError();
FindClose(hFind);
return dwError;
}
示例8: while
void CSetCurrentProject::OnOK()
{
int nSelected = -1;
POSITION p = m_listAvailableProjects.GetFirstSelectedItemPosition();
while(p)
{
nSelected = m_listAvailableProjects.GetNextSelectedItem(p);
}
if( nSelected >= 0 )
{
TCHAR szBuffer[1024];
DWORD cchBuf(1024);
LVITEM lvi;
lvi.iItem = nSelected;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT;
lvi.pszText = szBuffer;
lvi.cchTextMax = cchBuf;
m_listAvailableProjects.GetItem(&lvi);
for( CUInt i = 0; i < g_projects.size(); i++ )
{
if(g_projects[i]->m_isActive)
{
if( Cmp( szBuffer, g_projects[i]->m_name ) )
{
return; // no need to switch projects
}
}
}
//switch projects
//close curren open VScene
if(!ex_pVandaEngine1Dlg->OnMenuClickedNew(CTrue))
return;
//fist of all, mark all as inactive
for( CUInt i = 0; i < g_projects.size(); i++ )
{
g_projects[i]->m_isActive = CFalse;
}
//then find the selected project and mark it as active
for( CUInt i = 0; i < g_projects.size(); i++ )
{
if( Cmp( szBuffer, g_projects[i]->m_name ) )
{
g_projects[i]->m_isActive = CTrue;
break;
}
}
//change current directory
Cpy( g_currentProjectPath, g_projectsPath );
Append( g_currentProjectPath, szBuffer );
Append( g_currentProjectPath, "/" );
//clear VScene names
g_VSceneNamesOfCurrentProject.clear();
//then fill it with the VScenes of the selected project
for( CUInt i = 0; i < g_projects.size(); i++ )
{
if( g_projects[i]->m_isActive )
{
for( CUInt j = 0; j < g_projects[i]->m_sceneNames.size(); j++ )
{
g_VSceneNamesOfCurrentProject.push_back( g_projects[i]->m_sceneNames[j].c_str() );
}
}
}
CChar m_currentVSceneNameWithoutDot[MAX_NAME_SIZE];
if (Cmp(g_currentVSceneName, "\n"))
Cpy(m_currentVSceneNameWithoutDot, "Untitled");
else
{
Cpy(m_currentVSceneNameWithoutDot, g_currentVSceneName);
GetWithoutDot(m_currentVSceneNameWithoutDot);
}
CChar temp[256];
sprintf(temp, "%s%s%s%s%s", "Vanda Engine 1.4 (", szBuffer, " - ", m_currentVSceneNameWithoutDot, ")");
ex_pVandaEngine1Dlg->SetWindowTextA(temp);
//save the changes to projects.dat
FILE *ProjectsFilePtr;
CChar DATPath[MAX_NAME_SIZE];
sprintf( DATPath, "%s%s", g_projectsPath, "projects.dat" );
DeleteFile( DATPath );
ProjectsFilePtr = fopen( DATPath, "wb" );
if( !ProjectsFilePtr )
{
MessageBox( "Couldn't open 'assets/Projects/projects.dat' to save data!", "Vanda Engine Error", MB_OK | MB_ICONERROR);
//return;
}
CInt numProjects = (CInt)g_projects.size();
fwrite(&numProjects, sizeof(CInt), 1, ProjectsFilePtr);
fclose(ProjectsFilePtr);
for (CInt i = 0; i < numProjects; i++)
{
//.........這裏部分代碼省略.........
示例9: Shortcut_FixStartup
BOOL Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
{
TCHAR szShortcut[ MAX_PATH + 10 ] = TEXT("");
BOOL bSuccess;
HKEY hk;
if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0)
{
DWORD dwSize = sizeof(szShortcut);
DWORD dwType = REG_SZ;
RegQueryValueEx (hk, TEXT("Common Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
if (szShortcut[0] == TEXT('\0'))
{
dwSize = sizeof(szShortcut);
dwType = REG_SZ;
RegQueryValueEx (hk, TEXT("Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
}
RegCloseKey (hk);
}
if (szShortcut[0] == TEXT('\0'))
{
GetWindowsDirectory (szShortcut, MAX_PATH);
lstrcat (szShortcut, TEXT("\\Start Menu\\Programs\\Startup"));
}
lstrcat (szShortcut, TEXT("\\"));
lstrcat (szShortcut, pszLinkName);
TCHAR szSource[ MAX_PATH ];
GetModuleFileName (GetModuleHandle(NULL), szSource, MAX_PATH);
if (fAutoStart)
{
DWORD code, len, type;
TCHAR szParams[ 64 ] = TEXT(AFSCREDS_SHORTCUT_OPTIONS);
code = RegOpenKeyEx(HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY,
0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk);
if (code == ERROR_SUCCESS) {
len = sizeof(szParams);
type = REG_SZ;
code = RegQueryValueEx(hk, "AfscredsShortcutParams", NULL, &type,
(BYTE *) &szParams, &len);
RegCloseKey (hk);
}
if (code != ERROR_SUCCESS) {
code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk);
if (code == ERROR_SUCCESS) {
len = sizeof(szParams);
type = REG_SZ;
code = RegQueryValueEx(hk, "AfscredsShortcutParams", NULL, &type,
(BYTE *) &szParams, &len);
RegCloseKey (hk);
}
}
bSuccess = Shortcut_Create (szShortcut, szSource, "Autostart Authentication Agent", szParams);
}
else // (!g.fAutoStart)
{
bSuccess = DeleteFile (szShortcut);
}
return bSuccess;
}
示例10: AfxEnableControlContainer
BOOL CGpsxConsoleApp::InitInstance()
{
AfxEnableControlContainer();
openCommandWindow();
TCHAR result[MAX_PATH];
GetModuleFileName(NULL,result,MAX_PATH);//daemon
CString strProcess;
strProcess.Format(_T("%s"),result);
strProcess.MakeLower();
int nRet = strProcess.Find("daemon.exe");
if(__argc==1 && nRet>0 )//帶參數
{
printf("守護進程\r\nPress 'E' to exit\r\n");
nRet = strProcess.Find("daemon");
strProcess.Delete(nRet,6);
HANDLE hProcess=NULL;
DWORD dwProcessID=0;
while(1){
if((dwProcessID=_IsProcessExist(strProcess))==0){
int nRet = DeleteFile(strProcess);
if(nRet || GetLastError()==2){
if(CopyFile(result,strProcess,FALSE)){
PROCESS_INFORMATION pi;
_CreateProcess(strProcess,pi,FALSE,"");
hProcess = pi.hProcess;
dwProcessID = pi.dwProcessId;
}else{
}
}else{
// printf("deletefile %d,%d\r\n",nRet,GetLastError());
}
//printf("pi-->%d-->%d\r\n",hProcess,pi.dwProcessId);
}else{
//printf("IS-->%d\r\n",hProcess);
}
//Sleep(30*1000);
if(getch2(3*1000) == 101){
_KillProcess(dwProcessID);
int i=0;
do{
Sleep(i*100);
BOOL bRet = DeleteFile(strProcess);
printf("%s---%d\r\n",strProcess,bRet);
}while(i++<4);
return 1;
}
}
}
CString strLogServer("sonaps.logger.service.exe");
//*
HANDLE hProcess=NULL;
DWORD dwProcessID = 0;
if(!_IsProcessExist(strLogServer,FALSE)){
PROCESS_INFORMATION pi;
_CreateProcess(strLogServer,pi,FALSE,"");
}/**/
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
int nListenPort=GetPrivateProfileInt(_T("GPSSet"),_T("listenPort"),110,GetMgConfigFileName());
CString strTmp;
strTmp.Format(_T("GPSXCONSOLE_H__BA472566_78AA_%d"),nListenPort);
if(OpenMutex(MUTEX_ALL_ACCESS,FALSE,strTmp))
{
return FALSE;
}
else
{
CreateMutex(NULL,FALSE,strTmp);
}
// IDumper *pDumper = CreateDumper();
// if(pDumper)
// pDumper->SetExceptionFilter();
//自動抓取錯誤dump
CMiniDumper::SetExceptionFilter(MiniDumpWithFullMemory);
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CGpsxConsoleDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
//.........這裏部分代碼省略.........
示例11: copy
//.........這裏部分代碼省略.........
_tcscat(TempSrc,_T(".decrypt"));
if (!CopyFileEx(source, TempSrc, NULL, NULL, FALSE, COPY_FILE_ALLOW_DECRYPTED_DESTINATION))
{
CloseHandle (hFileSrc);
nErrorLevel = 1;
return 0;
}
_tcscpy(source, TempSrc);
}
if (lpdwFlags & COPY_RESTART)
{
_tcscpy(TrueDest, dest);
GetEnvironmentVariable(_T("TEMP"),dest,MAX_PATH);
_tcscat(dest,_T("\\"));
FileName = _tcsrchr(TrueDest,_T('\\'));
FileName++;
_tcscat(dest,FileName);
}
if (!IsExistingFile (dest))
{
TRACE ("opening/creating\n");
hFileDest =
CreateFile (dest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
}
else if (!append)
{
TRACE ("SetFileAttributes (%s, FILE_ATTRIBUTE_NORMAL);\n", debugstr_aw(dest));
SetFileAttributes (dest, FILE_ATTRIBUTE_NORMAL);
TRACE ("DeleteFile (%s);\n", debugstr_aw(dest));
DeleteFile (dest);
hFileDest = CreateFile (dest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
}
else
{
LONG lFilePosHigh = 0;
if (!_tcscmp (dest, source))
{
CloseHandle (hFileSrc);
return 0;
}
TRACE ("opening/appending\n");
SetFileAttributes (dest, FILE_ATTRIBUTE_NORMAL);
hFileDest =
CreateFile (dest, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
/* Move to end of file to start writing */
SetFilePointer (hFileDest, 0, &lFilePosHigh,FILE_END);
}
if (hFileDest == INVALID_HANDLE_VALUE)
{
CloseHandle (hFileSrc);
ConOutResPuts(STRING_ERROR_PATH_NOT_FOUND);
nErrorLevel = 1;
return 0;
}
示例12: ShellExecute
LRESULT CDlgView::onBnCLick( WPARAM wParam, LPARAM lParam )
{
CButtonCtrl *button = (CButtonCtrl*)lParam;
ADD_APP_DATA itemdata =(ADD_APP_DATA)button->m_pData;
if (itemdata.isLagerPic)
{
ShellExecute(NULL,"open",TEXT("http://8btc.com/thread-25079-1-1.html"),NULL,NULL, SW_SHOWNORMAL);
return 0;
}
if (itemdata.isInstall)
{
ADD_APP_DATA BtData;
GetAppUrlValue(itemdata.type,itemdata.appname,BtData);
if (BtData.appname != "" && BtData.version != itemdata.version)
{
if ( IDYES == UiFun::MessageBoxEx(_T("此程序有更新的版本,是否要下載") , UiFun::UI_LoadString("COMM_MODULE" , "COMM_TIP" ,theApp.gsLanguage) , MFB_YESNO|MFB_TIP ) )
{
string dowloufilepath = m_apppath + "\\"+strprintf("%s",itemdata.appname);
string dowloufileName = dowloufilepath + "\\"+strprintf("%s.zip",itemdata.appname);
string dowlouUrlPaht = m_urlpath +"/"+strprintf("%s",itemdata.appname);
string dowlouUrName = dowlouUrlPaht +"/"+strprintf("%s.zip",itemdata.appname);
if (Download(dowlouUrName.c_str(),dowloufileName.c_str()))
{
UnZipFile(dowloufileName,dowloufilepath);
///刪除下載的臨時文件
DeleteFile(dowloufileName.c_str());
button->m_pData.version = BtData.version;
MoidfyListAndSaveToFile(itemdata.type ,itemdata.appname,button->m_pData);
}
}
}
///打開應用程序
{
string appname = strprintf("%s",itemdata.appname)+".exe";
map<string,PROCESS_INFORMATION>::iterator it = m_process.find(itemdata.appname);
if (it != m_process.end()) /// 此應用程序已經打開,置頂
{
PROCESS_INFORMATION item = it->second;
HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,item.dwProcessId);
if(NULL != processHandle)
{
ProcessWindow procwin;
procwin.dwProcessId = item.dwProcessId;
procwin.hwndWindow = NULL;
// 查找主窗口
EnumWindows(EnumWindowCallBack, (LPARAM)&procwin);
//SetWindowPos(&this->wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
//顯示窗口
::ShowWindow(procwin.hwndWindow , SW_NORMAL);
//前端顯示
::SetForegroundWindow(procwin.hwndWindow );
::SetWindowPos( procwin.hwndWindow ,0,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
CloseHandle(processHandle);
return 0;
}
}
string appfileexe = m_apppath + "\\"+strprintf("%s",itemdata.appname)+"\\"+strprintf("%s",itemdata.appname)+strprintf("\\%s",itemdata.appname)+".exe";
/// 配置文件安裝了,但是找不到exe,重新設置配置文件沒有安裝
if (_access(appfileexe.c_str(),0) == -1)
{
button->m_pData.isInstall = false;
MoidfyListAndSaveToFile(itemdata.type ,itemdata.appname,button->m_pData);
return 0;
}
PROCESS_INFORMATION app_pi;
STARTUPINFOA si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow =SW_HIDE;//SW_HIDE; //SW_SHOW;
if(!CreateProcessA(NULL,(LPSTR)appfileexe.c_str(),NULL,NULL,FALSE,0,NULL,NULL,&si,&app_pi))
{
int n = GetLastError();
AfxMessageBox(_T("CreateProcessA sever error!"));
LogPrint("INFO", "開啟服務端程序失敗\n");
exit(1);
}
CloseHandle(app_pi.hProcess);
CloseHandle(app_pi.hThread);
m_process[itemdata.appname]=app_pi;
}
} else { /// 下載可執行程序
string dowloufilepath = m_apppath + "\\"+strprintf("%s",itemdata.appname);
string dowloufileName = dowloufilepath + "\\"+strprintf("%s.zip",itemdata.appname);
string dowlouUrlPaht = m_urlpath +"/"+strprintf("%s",itemdata.appname);
string dowlouUrName = dowlouUrlPaht +"/"+strprintf("%s.zip",itemdata.appname);
if (Download(dowlouUrName.c_str(),dowloufileName.c_str()))
{
UnZipFile(dowloufileName,dowloufilepath);
///刪除下載的臨時文件
DeleteFile(dowloufileName.c_str());
button->m_pData.isInstall = true;
//// 替換圖片
{
string filepathe;
//.........這裏部分代碼省略.........
示例13: Cleanup
HRESULT CSXFile::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name)
{
//////////////////////////////////////////////////////////////////////////
// SetFilename
//////////////////////////////////////////////////////////////////////////
if(strcmp(Name, "SetFilename")==0){
Stack->CorrectParams(1);
char* Filename = Stack->Pop()->GetString();
Cleanup();
CBUtils::SetString(&m_Filename, Filename);
Stack->PushNULL();
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// OpenAsText / OpenAsBinary
//////////////////////////////////////////////////////////////////////////
else if(strcmp(Name, "OpenAsText")==0 || strcmp(Name, "OpenAsBinary")==0){
Stack->CorrectParams(1);
Close();
m_Mode = Stack->Pop()->GetInt(1);
if(m_Mode<1 || m_Mode>3)
{
Script->RuntimeError("File.%s: invalid access mode. Setting read mode.", Name);
m_Mode = 1;
}
if(m_Mode==1)
{
m_ReadFile = Game->m_FileManager->OpenFile(m_Filename);
if(!m_ReadFile)
{
//Script->RuntimeError("File.%s: Error opening file '%s' for reading.", Name, m_Filename);
Close();
}
else m_TextMode = strcmp(Name, "OpenAsText")==0;
}
else
{
if(strcmp(Name, "OpenAsText")==0)
{
if(m_Mode==2) m_WriteFile = fopen(m_Filename, "w+");
else m_WriteFile = fopen(m_Filename, "a+");
}
else
{
if(m_Mode==2) m_WriteFile = fopen(m_Filename, "wb+");
else m_WriteFile = fopen(m_Filename, "ab+");
}
if(!m_WriteFile)
{
//Script->RuntimeError("File.%s: Error opening file '%s' for writing.", Name, m_Filename);
Close();
}
else m_TextMode = strcmp(Name, "OpenAsText")==0;
}
if(m_ReadFile || m_WriteFile) Stack->PushBool(true);
else Stack->PushBool(false);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// Close
//////////////////////////////////////////////////////////////////////////
else if(strcmp(Name, "Close")==0){
Stack->CorrectParams(0);
Close();
Stack->PushNULL();
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// SetPosition
//////////////////////////////////////////////////////////////////////////
else if(strcmp(Name, "SetPosition")==0){
Stack->CorrectParams(1);
if(m_Mode==0)
{
Script->RuntimeError("File.%s: File is not open", Name);
Stack->PushBool(false);
}
else
{
int Pos = Stack->Pop()->GetInt();
Stack->PushBool(SetPos(Pos));
}
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// Delete
//////////////////////////////////////////////////////////////////////////
else if(strcmp(Name, "Delete")==0){
Stack->CorrectParams(0);
Close();
Stack->PushBool(DeleteFile(m_Filename)!=FALSE);
return S_OK;
}
//.........這裏部分代碼省略.........
示例14: UpdateMPD
void UpdateMPD(char *pszOldFileName, char *pszNewFileName, int nPid)
{
int error;
char pszStr[4096];
HANDLE hMPD;
//FILE *fout;
//fout = fopen("c:\\temp\\update.out", "w");
// Open a handle to the running service
hMPD = OpenProcess(SYNCHRONIZE, FALSE, nPid);
if (hMPD == NULL)
{
error = GetLastError();
Translate_Error(error, pszStr);
//fprintf(fout, "OpenProcess(%d) failed, %s\n", nPid, pszStr);
//fclose(fout);
CloseHandle(hMPD);
return;
}
// Stop the service
CmdStopService();
// Wait for the service to exit
if (WaitForSingleObject(hMPD, 20000) != WAIT_OBJECT_0)
{
error = GetLastError();
Translate_Error(error, pszStr);
//fprintf(fout, "Waiting for the old mpd to stop failed. %s\n", pszStr);
//fclose(fout);
CloseHandle(hMPD);
return;
}
CloseHandle(hMPD);
// Delete the old service
if (!DeleteFile(pszOldFileName))
{
error = GetLastError();
Translate_Error(error, pszStr);
//fprintf(fout, "DeleteFile(%s) failed.\nError: %s\n", pszOldFileName, pszStr);
//fclose(fout);
return;
}
// Move the new service to the old service's spot
if (!MoveFile(pszNewFileName, pszOldFileName))
{
error = GetLastError();
Translate_Error(error, pszStr);
//fprintf(fout, "MoveFile(%s,%s) failed.\nError: %s\n", pszNewFileName, pszOldFileName, pszStr);
//fclose(fout);
return;
}
char szExe[1024];
if (!GetModuleFileName(NULL, szExe, 1024))
{
Translate_Error(GetLastError(), pszStr);
//fprintf(fout, "GetModuleFileName failed.\nError: %s\n", pszStr);
return;
}
STARTUPINFO sInfo;
PROCESS_INFORMATION pInfo;
GetStartupInfo(&sInfo);
_snprintf(pszStr, 4096, "\"%s\" -startdelete \"%s\"", pszOldFileName, szExe);
//fprintf(fout, "launching '%s'\n", pszStr);
if (!CreateProcess(NULL,
pszStr,
NULL, NULL, FALSE,
DETACHED_PROCESS,
NULL, NULL,
&sInfo, &pInfo))
{
error = GetLastError();
//fprintf(fout, "CreateProcess failed for '%s'\n", pszStr);
Translate_Error(error, pszStr);
//fprintf(fout, "Error: %s\n", pszStr);
//fclose(fout);
return;
}
CloseHandle(pInfo.hProcess);
CloseHandle(pInfo.hThread);
//fclose(fout);
}
示例15: GetTempPath
fsInternetResult vmsMaliciousDownloadChecker::Check(LPCTSTR pszUrl)
{
TCHAR szTmpPath [MY_MAX_PATH];
TCHAR szTmpFile [MY_MAX_PATH];
m_bNeedStop = false;
GetTempPath (_countof (szTmpPath), szTmpPath);
GetTempFileName (szTmpPath, _T("fdm"), 0, szTmpFile);
CString strUrl;
strUrl.Format (_T("http://fdm.freedownloadmanager.org/fromfdm/url.php?url=%s"), EncodeUrl (pszUrl));
vmsSimpleFileDownloader dldr;
m_dldr = &dldr;
if (m_bNeedStop) {
DeleteFile (szTmpFile);
return IR_S_FALSE;
}
dldr.Download (strUrl, szTmpFile);
while (dldr.IsRunning ())
Sleep (50);
m_dldr = NULL;
if (dldr.GetLastError ().first != IR_SUCCESS) {
DeleteFile (szTmpFile);
return dldr.GetLastError ().first;
}
if (m_bNeedStop) {
DeleteFile (szTmpFile);
return IR_S_FALSE;
}
HANDLE hFile = CreateFile (szTmpFile, GENERIC_READ, 0, NULL, OPEN_EXISTING,
FILE_FLAG_DELETE_ON_CLOSE, NULL);
ASSERT (hFile != INVALID_HANDLE_VALUE);
if (hFile == INVALID_HANDLE_VALUE) {
DeleteFile (szTmpFile);
return IR_ERROR;
}
char szBuf [1000];
DWORD dwSize = 0;
ReadFile (hFile, szBuf, sizeof (szBuf), &dwSize, NULL);
CloseHandle (hFile);
if (dwSize == 0)
{
m_cOpinions = 0;
m_cMalOpinions = 0;
m_fRating = 0;
m_strVirusCheckResult = _T("");
}
else
{
szBuf [dwSize] = 0;
char szVCR [10000];
sscanf (szBuf, "%d %f %d %s", &m_cOpinions, &m_fRating, &m_cMalOpinions, szVCR);
std::wstring sRes;
AnsiToUni(szBuf, sRes);
m_strVirusCheckResult = sRes.c_str();
}
return IR_SUCCESS;
}