LRESULT CDeskLnkDlg::OnApplyMessage(WPARAM wParam, LPARAM lParam)
{
	if (m_bModify)
	{
		i8desk::CDbMgr* pDbMgr = reinterpret_cast<CConsoleDlg*>(AfxGetMainWnd())->m_pDbMgr;
		std::string ErrInfo;
		if (!pDbMgr->DelBootTask(brShortcut, ErrInfo))
		{
			AfxMessageBox(ErrInfo.c_str());
			return FALSE;
		}

		// 写入开机任务网址快捷方式
		for (int idx=0; idx<m_lstDeskLnk.GetItemCount(); idx++)
		{
			i8desk::tagBootTask Task;
			char* pGuid = reinterpret_cast<char*>(m_lstDeskLnk.GetItemData(idx));
			i8desk::SAFE_STRCPY(Task.UID, pGuid);
			Task.AreaType = i8desk::TASK_AREA_ALL;
			CLEAR_STRING(Task.AreaParam);
			Task.Type = brShortcut;
			Task.Flag = 2;
			i8desk::SAFE_STRCPY(Task.Content, m_lstDeskLnk.GetItemText(idx, 0) 
				+ "|" + m_lstDeskLnk.GetItemText(idx, 1) 
				+ "|" + m_lstDeskLnk.GetItemText(idx, 3)
				+ "|" + m_lstDeskLnk.GetItemText(idx, 2));			
			if (!pDbMgr->AddBootTask(&Task, ErrInfo))
			{
				AfxMessageBox(ErrInfo.c_str());
				return FALSE;
			}
		}


		// 写入开机任务类别快捷方式
		i8desk::std_string strName;
		for(int idx = 0; idx < m_lstDeskClassLnk.GetItemCount(); idx++)
		{
			BOOL bChecked = m_lstDeskClassLnk.GetCheck(idx);

			if( bChecked == TRUE )
			{
				strName += m_lstDeskClassLnk.GetItemText(idx, 2) + _T("|");
			}
		}

		GetConsoleDlg()->m_pDbMgr->SetOption(_T("ClassShortcuts"), strName);

		m_bModify = FALSE;
	}
	return TRUE;
}
Beispiel #2
0
int sf_handleString(SaveFile* file, char* string){
	unsigned int bytes=0;
	sprintf(lastErrorDetected, "");
	if(! file ){
		sprintf(lastErrorDetected, "File input is null");
		return 0;
	}

	if( string == 0 ){
		sprintf(lastErrorDetected, "String is null");
		return 0;
	}

	if( file->saving ){
		unsigned long size = strlen(string);
		char* encryptedString =0;
		int res = 0;
		encryptedString = malloc(sizeof(char)*size +1);
		if(! encryptedString ) {
			sprintf(lastErrorDetected, "Failed to allocate temporary string");
			return 0;
		}
		memset(encryptedString, 0, sizeof(char)*size+1);
		strcpy(encryptedString, string);

		res = otp_encryptString(&encryptedString, file->key, file->keySize);
		if(! res ){
			CLEAR_STRING(encryptedString);
			sprintf(lastErrorDetected, "Failed to encrypt string, OTP reason: %s", otp_getLastError());
			return 0;
		}

		bytes = fwrite (&size, sizeof(unsigned long), 1, file->file);
		if( bytes != 1 ){
			CLEAR_STRING(encryptedString);
			sprintf(lastErrorDetected, "Failed to write string length");
			return 0;
		}
		md5_append(&file->state, (unsigned char*)&size, sizeof(unsigned long) );
		file->bytesWritten += sizeof(unsigned long);

		bytes = fwrite (encryptedString, sizeof(char), size, file->file);
		if( bytes != size ){
			CLEAR_STRING(encryptedString);
			sprintf(lastErrorDetected, "Failed to write whole string (%i of %i)", bytes, size);
			return 0;
		}
		md5_append(&file->state, encryptedString, size );
		file->bytesWritten += size;

		CLEAR_STRING(encryptedString);
	} else {
		unsigned long size = 0;
		int res = 0;
		//unsigned int inputsize = 0;

		bytes = fread (&size, sizeof(unsigned long), 1, file->file);
		if( bytes != 1 ){
			sprintf(lastErrorDetected, "Failed to read string length");
			return 0;
		}
		// check length of the input string length
		/*
		inputsize = sizeof(string); // this only gives the length of the current assigned data, and not the total sizeof the string

		if( inputsize < size+1 ){
			sprintf(lastErrorDetected, "The length of the input string needs to be atleast %i", size+1);
			return 0;
		}*/

		memset(string, 0, sizeof(char)*size + 1 );
		bytes = fread(string, sizeof(char), size, file->file);

		if( bytes != size ){
			sprintf(lastErrorDetected, "Failed to read whole string (%i of %i)", bytes, size);
			return 0;
		}

		res = otp_decryptString(&string, file->key, file->keySize);
		if(! res ){
			sprintf(lastErrorDetected, "Failed to decrypt string, OTP reason: %s", otp_getLastError());
			return 0;
		}
	}
	
	return 1;
}