예제 #1
0
bool AutoDownloader(char *path)
{
    int AbsolutePath = CheckFolder(Settings.DownloadFolder);

    if(AbsolutePath == RELATIVE)
        sprintf(path, "%s%s", Settings.BootDevice, Settings.DownloadFolder);
    else if(AbsolutePath == ABSOLUTE)
        sprintf(path, Settings.DownloadFolder);

    if (isValidPath(path))
        return true;
    return false;
}
예제 #2
0
BOOL CUpdateUtil::MakeClientXMLfile(CItemList *pItemListSoruce, LPCSTR lpszDestFilePath)
{
	if(!pItemListSoruce)
		return FALSE;

	CStdioFile writeFile;
	CString strFilePath = lpszDestFilePath;
	
	BOOL bFind = CheckFolder(strFilePath);
	if(bFind){
		if(!writeFile.Open(lpszDestFilePath, (CFile::modeCreate | CFile::modeWrite | CFile::typeText))){	
			SetLastError(UPDATE_ERROR_CANT_OPEN_XML_FILE);
			TRACE("UPDATE_ERROR_CANT_OPEN_XML_FILE : %s\n", lpszDestFilePath);
			return FALSE;
		}
	}
	else{
		return FALSE;
	}

	UTIL_CANCEL();
	CString strWriteLine, strFileName, strVersion, strDownPath, strCheckSum;
	strWriteLine = "<?xml version=\"1.0\" encoding=\"euc-kr\"?> \n";
	strWriteLine +=	"<update-data> \n\n";

	CPtrList* pPLServer = pItemListSoruce->GetPtrList();
	POSITION posServer = pPLServer->GetHeadPosition();
	while(posServer)
	{	
		UPDATE_DATA *psiServer = (UPDATE_DATA *)pPLServer->GetNext(posServer);
		strFileName = psiServer->Name;
		strVersion = psiServer->Version;
		strDownPath = psiServer->DownPath;
		strCheckSum = psiServer->CheckSum;
		strWriteLine +=	"\t<file name=\"" + strFileName + "\"> \n";
		strWriteLine += "\t\t<version>" + strVersion + "</version> \n";
		strWriteLine += "\t\t<downpath>" + strDownPath + "</downpath> \n";
		strWriteLine += "\t\t<checksum>" + strCheckSum + "</checksum> \n";
		strWriteLine += "\t</file> \n\n";
	}
	
	strWriteLine +=	"</update-data>";	
	writeFile.WriteString(strWriteLine);
	writeFile.Close();
//	TRACE("Write Xml File Success \n Contents : \n%s\n", strWriteLine);
	return TRUE;
}
예제 #3
0
int CUpdateUtil::CheckFile(CString strPath)
{
	int retval = UPDATE_FILECHECK_RESULT_ERROR;
	
	BOOL bFind = CheckFolder(strPath);
	if(bFind){
		CStdioFile stdioOpenFile;		
		if( !stdioOpenFile.Open(strPath, CFile::modeRead | CFile::typeText) ){
			if(!stdioOpenFile.Open(strPath, CFile::modeCreate | CFile::typeText))
				retval =  UPDATE_FILECHECK_RESULT_ERROR;
			else
				retval = UPDATE_FILECHECK_RESULT_CREATE;
		}
		else{
			retval = UPDATE_FILECHECK_RESULT_EXIST;
		}
		stdioOpenFile.Close();
	}
	else{
		retval = UPDATE_FILECHECK_RESULT_ERROR;
	}

	return retval;
}
예제 #4
0
CString CHttpFileDownload::GetDownPath()
{
	switch (m_nDownMethod){
		case HTTP_DOWNLOAD_PATH_EXECUTE:
			m_strDownPath = GetExecutePath();
			break;

		case HTTP_DOWNLOAD_PATH_TEMP:
			m_strDownPath = GetTempPath();
			break;
		
		case HTTP_DOWNLOAD_PATH_USER:
			if(SetDownPath(m_strDownPath)){
				if(!CheckFolder(m_strDownPath))
					m_strDownPath = "";
			}
			break;
		
		default:
			m_strDownPath = "";
	}

	return m_strDownPath;
}
예제 #5
0
int FileSaverUnit::save(const unsigned char *buffer)
{
	PacketHeader *header = (PacketHeader *)buffer;
	if (header->block_offset != receive_block + 1)
	{
		// 说明读取网卡时丢包
		return -1;
	}

	if (header->check_sum != check_sum(buffer + sizeof(PacketHeader), header->data_length))
	{
		// 校验包失败
		WriteLog("接收到的包校验失败");
		return -1;
	}

	memcpy(this->buffer + this->receive_length, buffer + sizeof(PacketHeader), header->data_length);
	this->receive_block++;
	this->receive_length += header->data_length;

	// 接收文件完毕后保存文件
	if (this->receive_block == block_num)
	{
		std::string new_filename;
		new_filename = filename;
		new_filename += ".recv";
		// 创建目录
		std::string path = new_filename.substr(0, new_filename.find_last_of("/"));
		CheckFolder(path.c_str());
		FILE *file = fopen(new_filename.c_str(), "wb+");
		fwrite(this->buffer, this->file_length, 1, file);
		fclose(file);
		return 2;
	}
	return 1;
}
예제 #6
0
//=============================================================================================
//      Проверка файла на наличие (имеем в виду, что может не существовать директории)
//=============================================================================================
void TFolderCheck::CheckFileExist(LPTSTR sPath, LPTSTR sFile)
{

char sUpdatePath[MAX_PATH]="C:\\WebClient\\";
Application->ProcessMessages();

int n;
        string *dirtxt=FoLi->ListFolder("toupdate");                     //???????? ?????, ??????? ?? ????? ????????
        //char *dbuf = new char[strlen(dirtxt[i].c_str())];
        char dbuf [MAX_PATH];
        for(int i=0;i<20;i++)
        {
        strcpy(dbuf,dirtxt[i].c_str());
		n=strlen(dbuf);
              //  Log->Write(dbuf);

        if (!n==0)
                if (strstr(sPath,dirtxt[i].c_str()))
                         {
	sUpdatePath[strlen(sUpdatePath)-1]='\0';
        strcat(sUpdatePath,strstr(sPath,dirtxt[i].c_str()));
  }
  }

  if (! ExceptionList(sPath))
  if (! FileExists(strcat(sUpdatePath,sFile)) )
                                 {      //  Log->Write("sPath : "+AnsiString(sPath));
                                      //  Log->Write("sUpdatePath : "+AnsiString(sUpdatePath));

                                        sUpdatePath[strlen(sUpdatePath)-strlen(strrchr(sUpdatePath,'\\'))]='\0';
                                        Log->Write("sUUUUPath : "+AnsiString(sUpdatePath));
                                        char mypath[MAX_PATH];
                                        strcpy(mypath,sUpdatePath);
                                        CheckFolder(mypath,0,0);
                                        strcat(sUpdatePath,"\\");
                                        strcat(sUpdatePath,sFile);
                                        strcat(sPath,sFile);



                                      // Log->Write("sFile : "+AnsiString(sFile));
                                      // Log->Write("sPath : "+AnsiString(sPath));
                                      // Log->Write("sUpdatePath : "+AnsiString(sUpdatePath));
                                      CopyFile(sPath,sUpdatePath,false);
                                      sPath[strlen(sPath) - strlen(sFile)] = '\0';     //восстанавливаем длину
                                      sUpdatePath[strlen(sUpdatePath) - strlen(sFile)] = '\0';



                                        //Log->Write("If file exists PATH - "+AnsiString(sPath));
                                       // Log->Write("If file exists sUpdatePath - "+AnsiString(sUpdatePath));
                                      //  }


                                 }
                      else
                      {
								
                                ReadingBinary(sUpdatePath,strcat(sPath,sFile));
                                sPath[strlen(sPath) - strlen(sFile)] = '\0';
                           //     rez++;
                               // Form1->Label10->Caption = rez;
                                }
                                
}