Exemplo n.º 1
0
bool NFile::remove( Path filename )
{
#ifdef CAESARIA_PLATFORM_WIN
  BOOL result = DeleteFileA( filename.toString().c_str() );
  if( !result )
  {
    int error = GetLastError();
    //Logger::warning( "Error[%d] on removed file %s", error, filename.toString().c_str() );
  }
  return result;
#elif defined(CAESARIA_PLATFORM_UNIX) || defined(CAESARIA_PLATFORM_HAIKU)
  int result = ::remove( filename.toString().c_str() );
  return (result == 0);
#endif
}
Exemplo n.º 2
0
void CleanUp(HANDLE hFile)
{
    if (CloseHandle(hFile) != TRUE)
    {
        Fail("GetFileSizeEx: ERROR -> Unable to close file \"%s\".\n"
             " Error is %d\n", 
            szTextFile, GetLastError());
    }
    if (!DeleteFileA(szTextFile))
    {
        Fail("GetFileSizeEx: ERROR -> Unable to delete file \"%s\".\n"
             " Error is %d\n", 
            szTextFile, GetLastError());
    }
}
Exemplo n.º 3
0
void FileImpl::removeImpl()
{
	poco_assert (!_path.empty());

	if (isDirectoryImpl())
	{
		if (RemoveDirectoryA(_path.c_str()) == 0) 
			handleLastErrorImpl(_path);
	}
	else
	{
		if (DeleteFileA(_path.c_str()) == 0)
			handleLastErrorImpl(_path);
	}
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
	if (argc != 2 || stricmp(INSTALL_COMMAND, argv[1]) != 0 && stricmp(UNINSTALL_COMMAND, argv[1]) != 0) {
		MessageBoxA(NULL, "Usage:\n  drvsetup install - install driver\n  drvsetup uninstall - uninstall driver\n", "Information", MB_OK | MB_ICONINFORMATION);
		return 1;
	}
	if (stricmp(UNINSTALL_COMMAND, argv[1]) == 0) {
		UnregisterDriver();
		char sysRoot[MAX_PATH];
		char pathName[MAX_PATH];
		GetEnvironmentVariableA("SYSTEMROOT", sysRoot, MAX_PATH);
		strncpy(pathName, sysRoot, MAX_PATH);
		strncat(pathName, "/SYSTEM32/mt32emu.dll", MAX_PATH);
		if (!DeleteFileA(pathName)) {
			// Driver can't be deleted, register pending deletion
			MoveFileExA(pathName, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
		}
		return 0;
	}
	char sysRoot[MAX_PATH];
	char pathName[MAX_PATH];
	char oldName[MAX_PATH];
	GetEnvironmentVariableA("SYSTEMROOT", sysRoot, MAX_PATH);
	strncpy(pathName, sysRoot, MAX_PATH);
	strncat(pathName, "/SYSTEM32/mt32emu.dll", MAX_PATH);
	strncpy(oldName, sysRoot, MAX_PATH);
	strncat(oldName, "/SYSTEM32/mt32emu.old", MAX_PATH);
	DeleteFileA(oldName);
	MoveFileA(pathName, oldName);
	int setupPathLen = strrchr(argv[0], '\\') - argv[0];
	strncpy(oldName, argv[0], setupPathLen);
	oldName[setupPathLen] = 0;
	strncat(oldName, "/mt32emu.dll", MAX_PATH);
	CopyFileA(oldName, pathName, FALSE);
	RegisterDriver();
	return 0;
}
Exemplo n.º 5
0
static void cleanup_pid_file()
{
        string pidfile = PID_FILE;
#if defined(OS_WINDOWS_MOBILE) || defined(OS_WINDOWS_VISTA)
	wchar_t *wpidfile = strtowstr_alloc(pidfile.c_str());
	if (wpidfile) {
		DeleteFile(wpidfile);
		free(wpidfile);
	}
#elif defined(OS_WINDOWS)
	DeleteFileA(pidfile.c_str());
#else
	unlink(pidfile.c_str());
#endif
}
Exemplo n.º 6
0
// Removes object from disk and memory
bool Cleaner::RemoveFile(QString filepath)
{

	// use client0::RemoveFile
	return DeleteFileA(filepath.toAscii().constData());

// 	if(removed)
// 	{
// 		WorkLog::GetLog().printmain(QString("object was successfully removed: ") + filepath);
// 	} else 
// 	{
// 		WorkLog::GetLog().printmain(QString("warning! Object was not removed: ") + filepath);
// 	}

}
Exemplo n.º 7
0
BOOL DeleteFileUTF8(LPCTSTR path)
{
  if (WDL_HasUTF8(path) && GetVersion()< 0x80000000)
  {
    MBTOWIDE(wbuf,path);
    if (wbuf_ok)
    {
      BOOL rv=DeleteFileW(wbuf);
      MBTOWIDE_FREE(wbuf);
      return rv;
    }
    MBTOWIDE_FREE(wbuf);
  }
  return DeleteFileA(path);
}
Exemplo n.º 8
0
Arquivo: files.c Projeto: bilboed/wine
static void test_AdvInstallFile(void)
{
    HRESULT hr;
    HMODULE hmod;
    char CURR_DIR[MAX_PATH];
    char destFolder[MAX_PATH];

    hmod = LoadLibrary("setupapi.dll");
    if (!hmod)
    {
        skip("setupapi.dll not present\n");
        return;
    }

    FreeLibrary(hmod);

    GetCurrentDirectoryA(MAX_PATH, CURR_DIR);

    lstrcpyA(destFolder, CURR_DIR);
    lstrcatA(destFolder, "\\");
    lstrcatA(destFolder, "dest");

    createTestFile("source.txt");

    /* try invalid source directory */
    hr = pAdvInstallFile(NULL, NULL, "source.txt", destFolder, "destination.txt", 0, 0);
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
    ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");

    /* try invalid source file */
    hr = pAdvInstallFile(NULL, CURR_DIR, NULL, destFolder, "destination.txt", 0, 0);
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
    ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");

    /* try invalid destination directory */
    hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", NULL, "destination.txt", 0, 0);
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
    ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");

    /* try copying to nonexistent destination directory */
    hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder, "destination.txt", 0, 0);
    ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
    ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n");

    /* native windows screws up if the source file doesn't exist */

    /* test AIF_NOOVERWRITE behavior, asks the user to overwrite if AIF_QUIET is not specified */
    createTestFile("dest\\destination.txt");
    hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder,
                         "destination.txt", AIF_NOOVERWRITE | AIF_QUIET, 0);
    ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
    ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n");
    ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");

    DeleteFileA("source.txt");
}
Exemplo n.º 9
0
void NetworkPacketDumper::deleteAdapterFiles() {
	std::list<NetworkAdapter*>::iterator it;
	for(it = adapterList.begin(); it != adapterList.end(); it++)
	{
		string adapterName = (*it)->getAdapterName();
		char* szLogFileName = new char[1024];
		string logName = "logs\\";
		logName += adapterName;
		logName += ".pcap";
		GetFullPathNameA(logName.c_str(), 1024, szLogFileName, NULL);
		LOG(INFO, "NetworkdPacketDumper: deleting log files %s",logName.c_str());
		DeleteFileA(szLogFileName);
		delete [] szLogFileName;
	}
	
}
Exemplo n.º 10
0
int _tmain(int argc, _TCHAR* argv[])
{
    if (argc > 1 && argv[1])
    {
        char path[1000] {};
        WideCharToMultiByte(CP_UTF8, 0, argv[1], -1, path, 1000, 0, 0);
        std::string out(path);
        out.append(".temp");
        if (MoveFileA(path, out.c_str()) == TRUE)
        {
            Parse(out, path);
            DeleteFileA(out.c_str());
        }
    }
    return 0;
}
Exemplo n.º 11
0
void WINAPI SvcCtrlHandler(DWORD dwCtrl)
{
	switch (dwCtrl)
	{
	case SERVICE_CONTROL_STOP:
		ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
		DeleteFileA("\\\\.\\pipe\\TagServicePipe");
		SetEvent(ghSvcStopEvent);
		return;

	case SERVICE_CONTROL_INTERROGATE:
		break;

	default:
		break;
	}
}
Exemplo n.º 12
0
static void SetAvatar(HANDLE hContact, JABBER_LIST_ITEM *item, char *data, int len, DWORD format) {
	FILE* out;
	char filename[MAX_PATH];
	char md5[33];
	MD5 context;
	int i;
	md5_init(&context);
	md5_update(&context, data, len);
	md5_finalize(&context);
	if (format == PA_FORMAT_UNKNOWN && len > 4) {
		format = JabberGetPictureType(data);
	}
	for (i=0;i<16;i++) {
		char lo, hi;
		unsigned int j=context.state[i>>2];
		j>>=8*(i%4);
		j&=0xFF;
		lo = j & 0x0F;
		hi = j >> 4;
		hi = hi + ((hi > 9) ? 'a' - 10 : '0');
		lo = lo + ((lo > 9) ? 'a' - 10 : '0');
		md5[i*2] = hi;
		md5[i*2+1] = lo;
	}
	md5[i*2] = 0;
	if (item != NULL) {
		char *hash = item->avatarHash;
		item->avatarFormat = format;
		item->avatarHash = mir_strdup(md5);
		mir_free(hash);
	} else {
		jabberThreadInfo->avatarFormat = format;
		strcpy(jabberThreadInfo->avatarHash, md5);
	}
	TlenGetAvatarFileName(item, filename, sizeof filename );
	DeleteFileA(filename);
	out = fopen( filename, "wb" );
	if ( out != NULL ) {
		fwrite( data, len, 1, out );
		fclose( out );
		DBWriteContactSettingString(hContact, "ContactPhoto", "File", filename );
		DBWriteContactSettingString(hContact, jabberProtoName, "AvatarHash",  md5);
		DBWriteContactSettingDword(hContact, jabberProtoName, "AvatarFormat",  format);
	}
	ProtoBroadcastAck( jabberProtoName, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL , 0);
}
Exemplo n.º 13
0
BOOL CleanUp(HANDLE hFile, const char * fileName)
{
    BOOL bRc = TRUE;
    if (CloseHandle(hFile) != TRUE)
    {
        bRc = FALSE;
        Trace("WriteFile: ERROR -> Unable to close file \"%s\","
            " error: %ld.\n", fileName, GetLastError());
    }
    if (!DeleteFileA(fileName))
    {
        bRc = FALSE;
        Trace("WriteFile: ERROR -> Unable to delete file \"%s\","
            " error: %ld.\n", fileName, GetLastError());
    }
    return bRc;
}
Exemplo n.º 14
0
BOOL Cleanup(void)
{
    char FileName[20];
    int i;
    BOOL bRet = TRUE; // assume success

    // loop through all accesses, modes, dispositions and flags
    for (i=0; i<4*8*4*5; ++i) {
        sprintf(FileName, "test%03d.txt", i);
	if (DeleteFileA(FileName) == FALSE) {
	    if (GetLastError() != ERROR_FILE_NOT_FOUND) {
		bRet = FALSE;
	    }
	}
    }
    return bRet;
}
Exemplo n.º 15
0
    //--------------------------------
    bool Utils::deleteFile(const String &pathString)
    {
        SystemType type = getSystemType();

#ifdef COLLADABU_OS_WIN
        if (type != WINDOWS)
            return false;
        return DeleteFileA(pathString.c_str()) != FALSE;
#else
        if (type != POSIX)
            return false;
        char command[4097];
        sprintf(command, "rm -f \"%s\"", pathString.c_str());
        int status = system(command);
        return status == 0;
#endif
    }
Exemplo n.º 16
0
static void Cleanup(HANDLE hFile)
{
    if (!CloseHandle(hFile))
    {
        Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\". ", 
            "GetLastError returned %u.\n", 
            szTextFile,
            GetLastError());
    }
    if (!DeleteFileA(szTextFile))
    {
        Trace("SetEndOfFile: ERROR -> Unable to delete file \"%s\". ", 
            "GetLastError returned %u.\n", 
            szTextFile,
            GetLastError());
    }
}
Exemplo n.º 17
0
bool remove(const u::string &path, pathType type) {
    u::string &&fix = u::fixPath(path);
    if (type == kFile) {
#if defined(_WIN32)
        return DeleteFileA(&fix[0]) != 0;
#else
        return ::remove(&fix[0]) == 0;
#endif
    }

    // type == kDirectory
#if defined(_WIN32)
    return RemoveDirectoryA(&fix[0]) != 0;
#else
    return ::rmdir(&fix[0]) == 0;
#endif
}
Exemplo n.º 18
0
/*
 * Removes a directory entry.
 */
int
optk_unlink(const char *path)
{
#if defined OPTK_OS_WINDOWS

    return DeleteFileA(path) ? 0 : -1;

#elif defined OPTK_OS_UNIX || defined OPTK_OS_DOSISH

    return unlink(path);

#else  /* generic */

    return remove(path);

#endif
}
bool FileUtils::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
{
    CCASSERT(!path.empty(), "Invalid path");
    std::string oldPath = path + oldname;
    std::string newPath = path + name;

    // Rename a file
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
    std::regex pat("\\/");
    std::string _old = std::regex_replace(oldPath, pat, "\\");
    std::string _new = std::regex_replace(newPath, pat, "\\");
    if (MoveFileEx(std::wstring(_old.begin(), _old.end()).c_str(),
                   std::wstring(_new.begin(), _new.end()).c_str(),
                   MOVEFILE_REPLACE_EXISTING & MOVEFILE_WRITE_THROUGH))
    {
        return true;
    }
    return false;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    std::regex pat("\\/");
    std::string _old = std::regex_replace(oldPath, pat, "\\");
    std::string _new = std::regex_replace(newPath, pat, "\\");

    if(FileUtils::getInstance()->isFileExist(_new))
    {
        DeleteFileA(_new.c_str());
    }

    MoveFileA(_old.c_str(), _new.c_str());

    if (0 == GetLastError())
        return true;
    else
        return false;
#else
    int errorCode = rename(oldPath.c_str(), newPath.c_str());

    if (0 != errorCode)
    {
        CCLOGERROR("Fail to rename file %s to %s !Error code is %d", oldPath.c_str(), newPath.c_str(), errorCode);
        return false;
    }
    return true;
#endif
}
Exemplo n.º 20
0
bool UninstallDllFromSystem32(char *dst_filename)
{
	char system32[MAX_PATH];
	char dst_fullpath[MAX_PATH];
	char bak_fullpath[MAX_PATH];
	bool ret;

	if (Is64BitCode() || IsWow64() == false)
	{
		GetSystemDirectoryA(system32, sizeof(system32));
	}
	else
	{
		GetSystemWow64DirectoryA(system32, sizeof(system32));
	}

	SeStrCpy(dst_fullpath, sizeof(dst_fullpath), system32);
	SeStrCat(dst_fullpath, sizeof(dst_fullpath), "\\");
	SeStrCat(dst_fullpath, sizeof(dst_fullpath), dst_filename);

	SeStrCpy(bak_fullpath, sizeof(bak_fullpath), dst_fullpath);
	SeStrCat(bak_fullpath, sizeof(bak_fullpath), ".bak");

LABEL_RETRY:
	ret = DeleteFileA(dst_fullpath);
	if (ret == false)
	{
		char tmp[MAX_SIZE];

		wsprintfA(tmp,
			"Deleting the file \"%s\" failed.\r\n\r\n"
			"Make sure that there are no running programs using WinPcap DLL.",
			dst_fullpath);

		if (MessageBoxA(NULL, tmp, INSTALLER_TITLE, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY)
		{
			goto LABEL_RETRY;
		}
		return false;
	}

	MoveFileA(bak_fullpath, dst_fullpath);

	return true;
}
Exemplo n.º 21
0
Arquivo: query.c Projeto: bilboed/wine
static void test_SetupGetSourceInfo(void)
{
    char buffer[MAX_PATH], inf_filename[MAX_PATH];
    DWORD required;
    HINF hinf;
    BOOL ret;

    lstrcpyA(inf_filename, CURR_DIR);
    lstrcatA(inf_filename, "\\");
    lstrcatA(inf_filename, "test.inf");

    create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1);

    hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
    ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");

    required = 0;

    ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_PATH, buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetSourceInfoA failed\n");

    ok(required == 1, "unexpected required size: %d\n", required);
    ok(!lstrcmpA("", buffer), "unexpected result string: %s\n", buffer);

    required = 0;
    buffer[0] = 0;

    ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_TAGFILE, buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetSourceInfoA failed\n");

    ok(required == 28, "unexpected required size: %d\n", required);
    ok(!lstrcmpA("LANCOM\\LANtools\\lanconf.cab", buffer), "unexpected result string: %s\n", buffer);

    required = 0;
    buffer[0] = 0;

    ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_DESCRIPTION, buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetSourceInfoA failed\n");

    ok(required == 19, "unexpected required size: %d\n", required);
    ok(!lstrcmpA("LANCOM Software CD", buffer), "unexpected result string: %s\n", buffer);

    SetupCloseInfFile(hinf);
    DeleteFileA(inf_filename);
}
Exemplo n.º 22
0
Arquivo: run.c Projeto: Dimillian/wine
static BOOL WINAPI test_enum_proc(HMODULE module, LPCSTR type, LPSTR name, LONG_PTR param)
{
    const char *script_data, *ext;
    DWORD script_size, size;
    char file_name[MAX_PATH];
    HANDLE file;
    HRSRC src;
    BOOL res;

    trace("running %s test...\n", name);

    src = FindResourceA(NULL, name, type);
    ok(src != NULL, "Could not find resource %s: %u\n", name, GetLastError());
    if(!src)
        return TRUE;

    script_data = LoadResource(NULL, src);
    script_size = SizeofResource(NULL, src);
    while(script_size && !script_data[script_size-1])
        script_size--;

    ext = strrchr(name, '.');
    ok(ext != NULL, "no script extension\n");
    if(!ext)
      return TRUE;

    sprintf(file_name, "test%s", ext);

    file = CreateFileA(file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
            FILE_ATTRIBUTE_NORMAL, NULL);
    ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
    if(file == INVALID_HANDLE_VALUE)
        return TRUE;

    res = WriteFile(file, script_data, script_size, &size, NULL);
    CloseHandle(file);
    ok(res, "Could not write to file: %u\n", GetLastError());
    if(!res)
        return TRUE;

    run_test(file_name);

    DeleteFileA(file_name);
    return TRUE;
}
Exemplo n.º 23
0
int file_delete(std::string fname) {
    DWORD result = DeleteFileA(fname.c_str());

    switch(result) {
        case 0:
            return 0;
            break;
        case ERROR_FILE_NOT_FOUND:
            return 0;
            break;
        case ERROR_ACCESS_DENIED:
            return 0;
            break;
        default:
            return 1;
            break;
    }
}
Exemplo n.º 24
0
static void test_simple_enumerationA(void)
{
    BOOL ret;
    char source[MAX_PATH], temp[MAX_PATH];
    int enum_count = 0;

    GetTempPathA(sizeof(temp), temp);
    GetTempFileNameA(temp, "doc", 0, source);

    create_source_fileA(source, comp_cab_zip_multi, sizeof(comp_cab_zip_multi));

    ret = SetupIterateCabinetA(source, 0, simple_callbackA, &enum_count);
    ok(ret == 1, "Expected SetupIterateCabinetA to return 1, got %d\n", ret);
    ok(enum_count == sizeof(expected_files)/sizeof(char *),
       "Unexpectedly enumerated %d files\n", enum_count);

    DeleteFileA(source);
}
Exemplo n.º 25
0
bool remove(const path & p) {

	bool succeeded = true;
	
	if(is_directory(p)) {
		succeeded &= RemoveDirectoryA(p.string().c_str()) == TRUE;
		if(!succeeded) {
			LogWarning << "RemoveDirectoryA(" << p << ") failed! " << GetLastErrorString();
		}
	} else {
		succeeded &= DeleteFileA(p.string().c_str()) == TRUE;
		if(!succeeded) {
			LogWarning << "DeleteFileA(" << p << ") failed! " << GetLastErrorString();
		}
	}

	return succeeded;
}
Exemplo n.º 26
0
L00401068()
{
    intOrPtr _v20;                         // _cfa_ffffffec
    intOrPtr _v44;                         // _cfa_ffffffd4
    intOrPtr _v56;                         // _cfa_ffffffc8
    _unknown_ __ebp;                       // r6
    _unknown_ _t13;                        // _t13
    _unknown_ _t14;                        // _t14
    _unknown_ _t15;                        // _t15
    _unknown_ _t16;                        // _t16
    _unknown_ _t17;                        // _t17

    while(1) {
        __ebp = __esp;
        __esp = __esp - 112;
        __edx = 4209408;
        _push(__edx);
        _push(_v44);
        _push( *((intOrPtr*)(__edx + 652)));
        _push( *((intOrPtr*)(__edx + 316)));
        L00401234();
        _pop(__edx);
         *(__edx + 16) =  *(__edx + 16) | 1730769190;
        if(__edx > 28879) {
            break;
        }
    }
    _push(__edx);
    GetCommandLineA();
    _pop(__edx);
    _v20 = 5;
    while(1) {
        _v56 = _v56 - -1475381619;
        _v20 = _v20 - 1;
        if(_v20 == 0) {
            break;
        }
    }
    _push(__edx);
    DeleteFileA(0);
    _pop(__edx);
    __esp = __ebp;
    return;
}
Exemplo n.º 27
0
/*
 * Changes the name of a file path.
 */
int
optk_rename(const char *src_path, const char *dest_path, int clobber)
{
#if defined OPTK_OS_WINDOWS

    DWORD dwFlags;

#if !defined OPTK_OS_WIN64
    if (OPTK_OS_WINDOWS_IS_WIN9X())
    {
        /* MoveFileEx is not available under Win9X; use MoveFile. */
        if (MoveFileA(src_path, dest_path))
            return 0;
        if (!clobber)
            return -1;
        DeleteFileA(dest_path);
        return MoveFileA(src_path, dest_path) ? 0 : -1;
    }
#endif

    dwFlags = clobber ? MOVEFILE_REPLACE_EXISTING : 0;
    return MoveFileExA(src_path, dest_path, dwFlags) ? 0 : -1;

#elif defined OPTK_OS_UNIX

    if (!clobber)
    {
        if (access(dest_path, OPTK_TEST_FILE) >= 0)
            return -1;
    }
    return rename(src_path, dest_path);

#else  /* generic */

    if (optk_test(dest_path, "e") > 0)
    {
        if (!clobber)
            return -1;
        optk_unlink(dest_path);
    }
    return rename(src_path, dest_path);

#endif
}
Exemplo n.º 28
0
int WINAPI mWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
	PSTR szCmdParam, int iCmdShow)
{
    //if (!stricmp(szCmdParam, "-n")) //phc
	//editnpc = 1;
    //if (!stricmp(szCmdParam, "-r")) //phc
	random = 1;					  //phc	

    // First check to see if the file exists.
    //
    while (GetFileAttributesA("cityofheroes.exe") == INVALID_FILE_ATTRIBUTES) {
		PromptUserForCohLocation();
    }

    STARTUPINFO startup;
    memset(&startup, 0, sizeof(startup));
    startup.cb = sizeof(STARTUPINFO);
    memset(&pinfo, 0, sizeof(pinfo));

    if(!CreateProcessA("cityofheroes.exe", "cityofheroes.exe -project coh -noverify", NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP | CREATE_SUSPENDED | DETACHED_PROCESS, NULL, NULL, (LPSTARTUPINFOA)&startup, &pinfo)) {
		MessageBoxA(NULL, "Failed to launch process!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return 0;
    }

    // delete old crap previous version used
	BOOL blAtr = GetFileAttributesA("data\\charcreate.txt");
    if (blAtr)
		DeleteFileA("data\\charcreate.txt");

    RunPatch();

	//Inject my Dll

	DWORD dwPID = pinfo.dwProcessId ;
	m_hTargetProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);

	InjectDLL(_T("HookCostume.dll"));

	CloseHandle(m_hTargetProcess);

    ResumeThread(pinfo.hThread);
    return 0;
}
    /*
     *  DestroyDirectoryA
     *      WinAPI-like function that deletes the path @szPath fully
     */
    inline BOOL DestroyDirectoryA(LPCTSTR szPath)
    {
        ForeachFile(szPath, "*.*", false, [&szPath](ModLoaderFile& file)
        {
            CHAR szPathFile[MAX_PATH];
            const char* pPath = file.filename;
                
            sprintf(szPathFile, "%s\\%s", szPath, pPath);
                
            if(file.is_dir)
                DestroyDirectoryA(szPathFile);
            else
                DeleteFileA(szPathFile);

            return TRUE;
        });
        
        return RemoveDirectoryA(szPath);
    }
Exemplo n.º 30
0
void DumpCombo (HWND hComboBox, int bClear)
{
	FILE *f;
	int i, nComboIdx[SIZEOF_MRU_LIST];

	if (bClear)
	{
		DeleteFileA (GetConfigPath (TC_APPD_FILENAME_HISTORY));
		return;
	}

	f = fopen (GetConfigPath (TC_APPD_FILENAME_HISTORY), "w");
	if (f == NULL) return;

	XmlWriteHeader (f);
	fputs ("\n\t<history>", f);

	/* combo list part:- get mru items */
	for (i = 0; i < SIZEOF_MRU_LIST; i++)
		nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);

	/* combo list part:- write out mru items */
	for (i = 0; i < SIZEOF_MRU_LIST; i++)
	{
		char szTmp[MAX_PATH] = { 0 };
		 
		if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < sizeof (szTmp))
			SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);

		if (szTmp[0] != 0)
		{
			char q[MAX_PATH * 2] = { 0 };
			XmlQuoteText (szTmp, q, sizeof (q));

			fprintf (f, "\n\t\t<volume>%s</volume>", q);
		}
	}

	fputs ("\n\t</history>", f);
	XmlWriteFooter (f);
	fclose (f);
}