Esempio n. 1
0
int CXtTestApp::OnInitInstance(void)
{
	SetLabel( _T("CXtTestApp") );

	TCHAR szDir[MAX_PATH] = {0};
	GetExeDir(szDir);
	_tprintf( _T("GetExeDir:%s\n"), szDir );

	return FUN_RET_OK;
}
Esempio n. 2
0
// Open the file
VI_FILE *ViOpenFile(char *path)
{
	VI_FILE *f;
	// Validate arguments
	if (path == NULL)
	{
		return NULL;
	}

	if (ViIsInternetFile(path))
	{
		HINTERNET hHttpFile;
		HINTERNET hInternet = InternetOpenA(DEFAULT_USER_AGENT,
			INTERNET_OPEN_TYPE_PRECONFIG,
			NULL, NULL, 0);
		UINT size;
		UINT sizesize;

		if (hInternet == NULL)
		{
			return NULL;
		}

		hHttpFile = InternetOpenUrlA(hInternet, path, NULL, 0,
			INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD, 0);

		if (hHttpFile == NULL)
		{
			InternetCloseHandle(hInternet);
			return NULL;
		}

		size = 0;
		sizesize = sizeof(size);

		if (StartWith(path, "ftp://"))
		{
			// ftp
			DWORD high = 0;

			size = FtpGetFileSize(hHttpFile, &high);
		}
		else
		{
			UINT errorcode = 0;
			UINT errorcode_size = sizeof(errorcode);

			// http
			if (HttpQueryInfo(hHttpFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
				&size, &sizesize, NULL) == false)
			{
				size = 0;
			}

			if (HttpQueryInfo(hHttpFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
				&errorcode, &errorcode_size, NULL) == false ||
				(errorcode / 100) != 2)
			{
				// HTTP getting error
				InternetCloseHandle(hInternet);
				InternetCloseHandle(hHttpFile);
				return NULL;
			}
		}

		f = ZeroMalloc(sizeof(VI_FILE));
		f->InternetFile = true;
		f->hInternet = hInternet;
		f->hHttpFile = hHttpFile;
		f->FileSize = size;

		return f;
	}
	else
	{
		IO *io;
		char fullpath[MAX_PATH];
		char exedir[MAX_PATH];

		GetExeDir(exedir, sizeof(exedir));

		ConbinePath(fullpath, sizeof(fullpath), exedir, path);

		io = FileOpen(fullpath, false);
		if (io == NULL)
		{
			return NULL;
		}

		f = ZeroMalloc(sizeof(VI_FILE));
		f->InternetFile = false;
		f->FileSize = FileSize(io);
		f->io = io;

		return f;
	}
}
Esempio n. 3
0
// TODO REMOVE
std::wstring Sys::GetExeDirW()
{
	std::string exeDir = GetExeDir();
	return std::wstring(exeDir.begin(), exeDir.end());
}
Esempio n. 4
0
/*
	instead of using just "test.exe" as the file name
	(LPSTR)getFileNameOnly(s).c_str()
	I use the whole path.

	Looks much better in Winrar and with the MS Cab viewer as one ca see the entier file paths

	Except that it doesn't always work....*sigh*. So you'll have to use the filename
	to determine what the full path was.

*/
bool 
MakeCab(const std::wstring& in_Where, 
		const std::string& in_Why, 
		DWORD& o_NumFilesInCab, 
		const std::wstring& in_StrThisFileOnly,
		const bool in_bDontRecurse = false) 
{
	g_CurrentDescription			= in_Why;
	ERF							erf = { 0 };
	CCAB			 cab_parameters = { 0 };	
	client_state				 cs = { 0 };

	set_cab_parameters(&cab_parameters);

	HFCI hfci = FCICreate(
		&erf,
		file_placed,
		mem_alloc,
		mem_free,
        fci_open,
        fci_read,
        fci_write,
        fci_close,
        fci_seek,
        fci_delete,
		get_temp_file,
        &cab_parameters,
        &cs
	);

	if (hfci == NULL)
	{
		printf("FCICreate() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
		return false;
	}

	o_NumFilesInCab = 0;
	std::vector<std::wstring>	VecFiles;
	std::list<std::wstring>	    SkippedExtensions;

	if(in_StrThisFileOnly.empty())
	{
		if( GetFileCount(in_Where.c_str(), o_NumFilesInCab, VecFiles, SkippedExtensions, in_bDontRecurse) && o_NumFilesInCab)
		{
			wprintf(L"Ready to create a CAB using [%s] with [%d] files in it...\r\n", in_Where.c_str(),  o_NumFilesInCab);		
			printf("Destination CAB: [%s]\r\n", GetExeDir().c_str());
		}
		else
		{
			wprintf(L"Cannot perform under [%s]...Specify a valid, non-empty folder\r\n", in_Where.c_str());
			printf("Destination CAB: [%s]\r\n", GetExeDir().c_str());
			return false;
		}
	}
	else
	{
		++o_NumFilesInCab;
		VecFiles.push_back(in_StrThisFileOnly);
	}


	// For each file in 'in_Where' folder and subfolder, unless 'in_StrThisFileOnly' param was specified

	for each(std::wstring s in VecFiles)	
	{
		if (FALSE == FCIAddFile(
				hfci,
				(LPSTR)wide2Ansi(s).c_str(),		// file to add, can't be a folder, needs full path 
				(LPSTR)getFileNameOnly(s).c_str(),	// file name in cabinet file, and should not include any path information (e.g. “TEST.EXE”). 
				FALSE,						 //  specifies whether the file should be executed automatically when the cabinet is extracted 
				get_next_cabinet,
				progress,		// should point to a function which is called periodically by FCI so that the application may send a progress report to the user
				get_open_info,	// point to a function which opens a file and returns its datestamp, timestamp, and attributes
				COMPRESSION_TYPE))
			{
				printf("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
				TRACE3("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
				//FCIDestroy(hfci);
				//return false;
				// Try to keep a possible good file created so far...
				o_NumFilesInCab--;
			}
	}

	/*
	The FCIFlushCabinet API forces the current cabinet under construction to be completed immediately and written to disk.  
	Further calls to FCIAddFile will cause files to be added to another cabinet.  It is also possible that there exists pending 
	data in FCI’s internal buffers that will may require spillover into another cabinet, if the current cabinet has reached the 
	application-specified media size limit.
	*/

	if(o_NumFilesInCab > 0)
	{
		if (FALSE == FCIFlushCabinet(
			hfci,
			FALSE,				// The fGetNextCab flag determines whether the function pointed to by the supplied GetNextCab parameter, will be called.  
			get_next_cabinet,	// If fGetNextCab is TRUE, then GetNextCab will be called to obtain continuation information
			progress))
		{
			printf("FCIFlushCabinet() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
			FCIDestroy(hfci);
			return false;
		}
	}

    if (FCIDestroy(hfci) != TRUE)
	{
		printf("FCIDestroy() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
		return false;
	}

	return o_NumFilesInCab > 0;
}
Esempio n. 5
0
void set_cab_parameters(PCCAB cab_parms)
{
	// initialize it yourself using = { 0 };
	// memset(cab_parms, 0, sizeof(CCAB));

	/*
	The cb field, the media size, specifies the maximum size of a cabinet which will be created by FCI.  
	If necessary, multiple cabinets will be created.  To ensure that only one cabinet is created, a sufficiently large 
	number should be used for this parameter.
	*/
	cab_parms->cb = MEDIA_SIZE;

	/*
	The cbFolderThresh field specifies the maximum number of compressed bytes which may reside in a folder before a 
	new folder is created.  A higher folder threshold improves compression performance (since creating a new folder 
	resets the compression history), but increases random access time to the folder.
	*/
	cab_parms->cbFolderThresh = FOLDER_THRESHOLD;

	/*
	 * Don't reserve space for any extensions
	 */
	cab_parms->cbReserveCFHeader = 0;
	cab_parms->cbReserveCFFolder = 0;
	cab_parms->cbReserveCFData   = 0;

	/*
	 * We use this to create the cabinet name
	 */
	cab_parms->iCab = 1;

	/*
	 * If you want to use disk names, use this to
	 * count disks
	 */
	cab_parms->iDisk = 0;

	/*
	 * Choose your own number
	 */
	cab_parms->setID = 39;

	/*
	 * Only important if CABs are spanning multiple
	 * disks, in which case you will want to use a
	 * real disk name.
	 *
	 * Can be left as an empty string.
	 */
	strcpy(cab_parms->szDisk, "Espresso");

	/* 
		where to store the created CAB files 

		The szCabPath field should contain the complete path of where to create the cabinet (e.g. “C:\MYFILES\”).
	
	*/

	strncpy(cab_parms->szCabPath, GetExeDir().c_str(), CB_MAX_CAB_PATH);

	/* 
		store name of first CAB file 

		The szCab field should contain a string which contains the name of the first cabinet to be created (e.g. “APP1.CAB”).  
	
	*/
	store_cab_name(cab_parms->szCab, cab_parms->iCab);
}
Esempio n. 6
0
int main(int argc, const char* argv[])
{
	// 分析命令行选项
	CmdArgParser cmdParser("", TCtoC_str(CStrFormat(_T("服务版本: %d.%d.%d"), g_majorVer, g_minorVer, g_thirdVer)));

	CStringA sip;
	VERIFY(cmdParser.AddStr(
			sip, "-ip", "", "IP",
			"服务的TCP监听IP,默认监听本机所有IP"
			));

	int tcpPort = g_serveIPP.port_;
	VERIFY(cmdParser.AddInt(
			tcpPort, "-p",
			1, GET_INT_MAX_VALUE(WORD),
			tcpPort, "port",
			"服务的TCP监听端口"
			));

	if(!cmdParser.RunParse(argc, argv))
		return -1;

	if(!sip.IsEmpty())
	{
		if(!IsValidIP((const char*)sip, &g_serveIPP.ip_))
		{
			NPLogError((_T("非法ip参数: %s"), (LPCTSTR)CtoTC_str((const char*)sip)));
			return -1;
		}
	}
	g_serveIPP.port_ = tcpPort;

	//用户定义_S

	CPCC_Startup pcc;
	int rt_st = pcc.Startup();
	if(rt_st < 0)
	{
		return rt_st;
	}
	//

	//用户定义_E
	// 设置基本系统参数
#if defined(WIN32)
	SetCurrentDirectory(GetExeDir());
#endif
	tcps_SetLogPrint(LogPrint__, NULL);

	// 构造rpc服务对象
	// 可在构造PCC_CenterSessionMaker时传递一 void* 参数给会话对象
	// 如:PCC_CenterSessionMaker sessionMaker(param);
	// 在会话对象中可使用this->m_sessionMaker.m_userParameter获得
	PCC_CenterSessionMaker sessionMaker;
	iscm_IRPCServeMan* rpcMan = NULL;
	TCPSError err = iscm_MakeRPCServeMan(rpcMan, g_serveIPP.port_, g_serveIPP.ip_, &sessionMaker, TCPS_MAX_TOTAL_SESSIONS/2);
	if(TCPS_OK == err)
	{
		// 运行主循环
		NPLogInfo(("Running serve..."));
		struct TCheck
		{
			static BOOL RunCheck(void* /*param*/)
				{	return !g_exitFlag;	}
		};
#if defined(WIN32)
		typedef HWND (WINAPI* FNGetConsoleWindow)();
		FNGetConsoleWindow fnGetConsoleWindow
			= (FNGetConsoleWindow)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetConsoleWindow");
		HWND wnd;
		if(fnGetConsoleWindow && NULL!=(wnd=fnGetConsoleWindow()))
		{
			char ch[1024];
			int l = GetWindowTextA(wnd, ch, sizeof(ch)-16);
			char ippStr[32];
			GetIPPortTxt(g_serveIPP, ippStr);
			sprintf(ch+l, " - %s", ippStr);
			SetWindowTextA(wnd, ch);
		}
#endif
		RunMainLoop(TCheck::RunCheck, NULL);
		g_exitFlag = true;
		NPLogInfo(("Exiting serve..."));
	}
	else
	{
		NPLogError(("iscm_MakeRPCServeMan(%d) failed, %s(%d)", tcpPort, tcps_GetErrTxt(err), err));
	}

	// 析构rpc服务对象
	if(rpcMan)
		rpcMan->DeleteThis();

//#if defined(_NP_IS_X86) || defined(_NP_IS_X64)
//	NPCRT_API_SetPerformancePolicy(false, true);
//#endif

	// 销毁tcps/iscm库中所有的全局对象(拥有线程的)
	tcps_DestroyAllGlobalObjects();

	return 0;
}