예제 #1
0
파일: BlobMgmt.cpp 프로젝트: sylarhl/sqlgoy
wyBool
BlobMgmt::SaveToFile()
{
	OPENFILENAME	open;
	wyWChar         filename[MAX_PATH + 1] = {0};
	HANDLE			hfile = NULL;
	DWORD			dwbytesread;

	if(!m_piub->m_data)
    {
		yog_message(m_hwnddlg, _(L"Cannot write NULL value!"), pGlobals->m_appname.GetAsWideChar(), MB_OK | MB_ICONINFORMATION);
		return wyFalse;
	}

	memset(&open, 0, sizeof(open));

	open.lStructSize       = OPENFILENAME_SIZE_VERSION_400;
	open.hwndOwner         = m_hwnddlg;
	open.hInstance         = pGlobals->m_pcmainwin->GetHinstance();
	open.lpstrFilter       = L"All Files(*.*)\0*.*\0";
	open.lpstrCustomFilter =(LPWSTR)NULL;
	open.nFilterIndex      = 1L;
	open.lpstrFile         = filename;
	open.nMaxFile          = MAX_PATH;
	open.lpstrTitle        = L"Save As";
	open.Flags             = OFN_OVERWRITEPROMPT;
	
	if(! GetSaveFileName(&open))
	   return wyFalse;

	// else successfull.
	hfile = CreateFile((LPCWSTR)filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
						 NULL);	

	if(hfile == INVALID_HANDLE_VALUE)
	{
		DisplayErrorText(GetLastError(), _("Could not create file !"));
		return wyFalse;
	}

	VERIFY(WriteFile(hfile, m_piub->m_data, m_piub->m_datasize, &dwbytesread, NULL));
	CloseHandle(hfile);
	return wyTrue;
}
wyInt64
ImportBatch::SetInitProgressValues()
{
	wyWChar		importfile[MAX_PATH+1]={0};
	HWND		progress;
	DWORD		lowfilesize;
	DWORD		highfilesize;
	wyInt64		filesize = 0;
	HANDLE		handle;
	wyUInt32	incr;
	
	/* get the filename from the edit box */
	if(!SendMessage(m_hwndedit, WM_GETTEXT, MAX_PATH, (LPARAM)importfile))
		return false;

	handle  =  CreateFile(importfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
	if(handle == INVALID_HANDLE_VALUE)
    {
		DisplayErrorText(GetLastError(), _("Could not open file."));
		return false;
	}
	
	lowfilesize = GetFileSize(handle, &highfilesize);
	
	//if file size is > 4GB. then first 32 bits(LSB) is in lowfilesize and next 32 bits(MSB) in high filesize
	//converting these two 32 bits to 64 bits 
	filesize = ((wyInt64)highfilesize << 32) + lowfilesize;
		
	VERIFY(CloseHandle(handle));
	VERIFY(progress = GetDlgItem(m_hwnd, IDC_PROGRESS));

	SendMessage(progress,  PBM_SETRANGE32, 0, 0);
	UpdateWindow(progress);
	//setting the range of progressbar
	SendMessage(progress,  PBM_SETRANGE32, 0, ((filesize )/1024));

	//finding the increment value for the progress bar
	incr = ((filesize/1024)/100); 
	SendMessage(progress,  PBM_SETSTEP, (WPARAM)incr, 0); 
	
	return filesize;
}
예제 #3
0
DWORD create_driver_service(FILE* log,LPCTSTR ServiceName,LPCTSTR ServiceDescription,LPCTSTR ServicePath)
{
	SC_HANDLE SCM_Handle;
	SC_HANDLE ServiceHandle;
	DWORD ReturnValue = NO_ERROR;

	SCM_Handle=OpenSCManager(NULL,  /*local machine  */
		NULL,						/*active database*/
		SC_MANAGER_ALL_ACCESS);

	if (SCM_Handle==NULL)
	{
		ReturnValue = GetLastError();

		if (log != NULL)
		{
			fprintf(log,"Error opening Service Control Manager: ");
			DisplayErrorText(ReturnValue,log);
		}
		
		return ReturnValue;
	}

	ServiceHandle=CreateService(SCM_Handle,
					ServiceName,
					ServiceDescription,
					SERVICE_ALL_ACCESS,
					SERVICE_KERNEL_DRIVER,
					SERVICE_DEMAND_START,
					SERVICE_ERROR_NORMAL,
					ServicePath,
					NULL,
					NULL,
					NULL,
					NULL,
					NULL);

	if (ServiceHandle==NULL)
	{
		ReturnValue = GetLastError();

		if (log != NULL)
		{
			fprintf(log,"Error creating service %s: ",ServiceName);
			DisplayErrorText(ReturnValue,log);
		}

		if (!CloseServiceHandle(SCM_Handle))
		{
			if (log != NULL)
			{
				fprintf(log,"Error closing Service control Manager\n");
			}
		}
					
		return ReturnValue;
	}

	if (log != NULL)
	{
		fprintf(log,"Service %s successfully created.\n",ServiceName);
	}


	if (!CloseServiceHandle(ServiceHandle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error closing service %s.\n",ServiceName);
		}
	}


	if (!CloseServiceHandle(SCM_Handle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error closing Service control Manager\n");
		}
	}
	
	return ReturnValue;

}
예제 #4
0
DWORD start_service(FILE* log,LPCTSTR ServiceName)
{
	SC_HANDLE SCM_Handle;
	SC_HANDLE ServiceHandle;
	DWORD ReturnValue = NO_ERROR;

	SCM_Handle=OpenSCManager(NULL,  /*local machine  */
		NULL,						/*active database*/
		SC_MANAGER_ALL_ACCESS);

	if (SCM_Handle == NULL)
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error opening Service Control Manager: ");
			DisplayErrorText(ReturnValue,log);
		}
		return ReturnValue;
	}

	ServiceHandle=OpenService(SCM_Handle,
					ServiceName,
					SERVICE_ALL_ACCESS);


	if (ServiceHandle == NULL)
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error opening service %s: ",ServiceName);
			DisplayErrorText(ReturnValue,log);
		}

		if (!CloseServiceHandle(SCM_Handle))
		{
			if (log != NULL)
			{
				fprintf(log,"Error closing Service control Manager\n");
			}
		}
					
		return ReturnValue;
	}

	if (!StartService(ServiceHandle,0,NULL))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log, "Error starting service %s:",ServiceName);
			DisplayErrorText(ReturnValue,log);
		}
	}
	else
	{
		if (log != NULL)
		{
			fprintf(log,"Service %s successfully started\n",ServiceName);
		}
	}
	
	if (!CloseServiceHandle(ServiceHandle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error closing service %s\n",ServiceName);
		}
	}


	if (!CloseServiceHandle(SCM_Handle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error closing Service control Manager\n");
		}
	}
	
	return ReturnValue;

}
예제 #5
0
DWORD change_start_type_service(FILE* log,LPCTSTR ServiceName, DWORD StartType)
{
	SC_HANDLE SCM_Handle;
	SC_HANDLE ServiceHandle;
	DWORD ReturnValue = NO_ERROR;

	SCM_Handle=OpenSCManager(NULL,  /*local machine  */
		NULL,						/*active database*/
		SC_MANAGER_ALL_ACCESS);

	if (SCM_Handle == NULL)
	{
		if (log != NULL)
		{
			ReturnValue = GetLastError();
			fprintf(log,"Error opening Service Control Manager: ");
			DisplayErrorText(ReturnValue,log);
		}
		return ReturnValue;
	}

	ServiceHandle=OpenService(SCM_Handle,
					ServiceName,
					SERVICE_ALL_ACCESS);


	if (ServiceHandle == NULL)
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error opening service %s: ",ServiceName);
			DisplayErrorText(ReturnValue,log);
		}

		if (!CloseServiceHandle(SCM_Handle))
		{
			if (log != NULL)
			{
				fprintf(log,"Error closing Service control Manager\n");
			}
		}
					
		return ReturnValue;
	}

	if (!ChangeServiceConfig(ServiceHandle,
		SERVICE_NO_CHANGE,
		StartType,
		SERVICE_NO_CHANGE,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL))
	{
		ReturnValue = GetLastError();

		if (log != NULL)
		{
			fprintf(log, "Error changing start type for service %s:",ServiceName);
			DisplayErrorText(ReturnValue,log);
		}
	}
	else
	{
		if (log != NULL)
			fprintf(log,"Successfully changed start-type for service %s\n",ServiceName);
	}

	if (!CloseServiceHandle(ServiceHandle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error closing service %s\n",ServiceName);
		}
	}


	if (!CloseServiceHandle(SCM_Handle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
			fprintf(log,"Error closing Service control Manager\n");
	}
	
	return ReturnValue;

}
예제 #6
0
DWORD delete_service(FILE* log,LPCTSTR ServiceName)
{
	SC_HANDLE SCM_Handle;
	SC_HANDLE ServiceHandle;
	SERVICE_STATUS ServiceStatus;

	DWORD ReturnValue = NO_ERROR;

	SCM_Handle=OpenSCManager(NULL,  /*local machine  */
		NULL,						/*active database*/
		SC_MANAGER_ALL_ACCESS);

	if (SCM_Handle==NULL)
	{
		ReturnValue = GetLastError();
		if (log != NULL)	
		{
			fprintf(log,"Error opening Service Control Manager: ");
			DisplayErrorText(ReturnValue,log);
		}
		return ReturnValue;
	}

	ServiceHandle=OpenService(SCM_Handle,
					ServiceName,
					SERVICE_ALL_ACCESS);


	if (ServiceHandle==NULL)
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error opening Service Control Manager: ");
			DisplayErrorText(ReturnValue,log);
		}
		
		if (!CloseServiceHandle(SCM_Handle))
			if (log != NULL)
				fprintf(log,"Error closing Service control Manager\n");
					
		return ReturnValue;
	}

	ReturnValue=0;

	if (!ControlService(ServiceHandle,SERVICE_CONTROL_STOP,&ServiceStatus))
	{
		DWORD Err=GetLastError();

		if (Err != ERROR_SERVICE_NOT_ACTIVE)
		{
			if (log != NULL)
			{
				fprintf(log,"Error stopping service %s: ",ServiceName);
				DisplayErrorText(Err,log);
			}

			ReturnValue = Err;
		}
	}
	else
		if (log != NULL)
			fprintf(log,"Service %s successfully stopped\n",ServiceName);

	if (!DeleteService(ServiceHandle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error deleting service %s: ",ServiceName);
			DisplayErrorText(ReturnValue,log);
		}
		
	}
	else
	{
		if (log != NULL)
			fprintf(log,"Service %s successfully deleted\n",ServiceName);
	}
	
	if (!CloseServiceHandle(ServiceHandle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
		{
			fprintf(log,"Error closing service %s: ",ServiceName);
			DisplayErrorText(ReturnValue,log);
		}
	}


	if (!CloseServiceHandle(SCM_Handle))
	{
		ReturnValue = GetLastError();
		if (log != NULL)
			fprintf(log,"Error closing Service control Manager\n");
	}
	
	return ReturnValue;

}
예제 #7
0
파일: BlobMgmt.cpp 프로젝트: sylarhl/sqlgoy
wyBool
BlobMgmt::OpenFromFile()
{
	OPENFILENAME	open;
	wyWChar			filename[MAX_PATH+1] = {0};
	HANDLE			hfile = NULL;
	wyChar			*buffer = {0};
	DWORD			dwbytesread, filesize;
	wyString		bufferstr;

	memset(&open, 0, sizeof(open));

	open.lStructSize       = OPENFILENAME_SIZE_VERSION_400;
	open.hwndOwner         = m_hwnddlg;
	open.hInstance         = pGlobals->m_pcmainwin->GetHinstance();
	open.lpstrFilter       = L"All Files(*.*)\0*.*\0";
	open.lpstrCustomFilter =(LPWSTR)NULL;
	open.nFilterIndex      = 1L;
	open.lpstrFile         = filename;
	open.nMaxFile          = MAX_PATH;
	open.lpstrTitle        = L"Open File";
	
	if(! GetOpenFileName(&open))
	   return wyFalse;

	// else successfull.
	hfile = CreateFile((LPCWSTR)filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
						 NULL);	

	if(hfile == INVALID_HANDLE_VALUE)
	{
		DisplayErrorText(GetLastError(), _("Could not open file !"));
		return wyFalse;
	}

	VERIFY((filesize = GetFileSize(hfile, NULL))!= INVALID_FILE_SIZE);
	VERIFY (buffer =(wyChar*)malloc(filesize + 1));
	SetCursor(LoadCursor(NULL, IDC_WAIT));

	if(!ReadFile(hfile, buffer, filesize, &dwbytesread, NULL))
	{
		DisplayErrorText(GetLastError(), _("Could not open file. The data is not changed"));
		free(buffer);
		SetCursor(LoadCursor(NULL, IDC_ARROW));
		CloseHandle(hfile);
		return wyFalse;
	}

	*(buffer + dwbytesread)= NULL;

	SetCursor(LoadCursor(NULL, IDC_ARROW));

	// now we add the new buffer.
	if(m_newdata && m_newdata != m_olddata)
		free(m_newdata);
	
	m_newdata       = (wyChar *)buffer;
	m_newdatasize   = dwbytesread;
	
	/* store the old data too */
	m_piub->m_olddata		= m_piub->m_data;
	m_piub->m_olddatasize	= m_piub->m_datasize;
	m_piub->m_data			= m_newdata;
	m_piub->m_datasize		= dwbytesread;
	m_piub->m_isnull		= wyFalse;

	VERIFY(CloseHandle(hfile));

	// upddate with the new.
	ShowData(wyFalse);

	/* we need to do this after showdata coz showdata changes the modify flag to 0 */
	/* now if its text data then we set the text control modification flag */
	if(!memchr(buffer, 0, dwbytesread))
		SendMessage(m_hwndedit, EM_SETMODIFY, TRUE, 0);

	return wyTrue;
}
예제 #8
0
파일: Favorite.cpp 프로젝트: Fale/sqlyog
wyBool 
FavoriteBase::OnError(wyString errmsg)
{
    DisplayErrorText(::GetLastError(), errmsg.GetString());
    return wyFalse;
}