Exemple #1
0
DWORD _drv_action(int action, int version)
{
	static wchar_t restart_confirm[ ] = 
						L"You must restart your computer before the new settings will take effect.\n\n"
						L"Do you want to restart your computer now?";
	DWORD status = ERROR_INVALID_FUNCTION;

	switch (action) 
	{
		case DA_INSTAL: 
		{
			if ( dc_is_driver_installed() ) 
			{
				if ( __msg_q( HWND_DESKTOP, restart_confirm ) )
				{
					_reboot( );
				}
				status = NO_ERROR;
			} else
			{
				if ( __msg_q( HWND_DESKTOP, L"Install DiskCryptor driver?" ) )
				{
					if ( (status = dc_install_driver()) == NO_ERROR )
					{
						if ( __msg_q( HWND_DESKTOP, restart_confirm ) )
						{
							_reboot( );					
						}						
					}
				} else {
					status = NO_ERROR;
				}
			}
		}
		break;
		case DA_REMOVE: 
		{
			if ( dc_is_driver_installed() ) 
			{
				if ( (status = dc_remove_driver()) == NO_ERROR )
				{
					if ( __msg_q( HWND_DESKTOP, restart_confirm ) )
					{
						_reboot( );
					}
				}
			}
		}
		break;
		case DA_UPDATE: 
		{
			wchar_t up_atom[MAX_PATH];

			_snwprintf(up_atom, countof(up_atom), L"DC_UPD_%d", version);

			if (GlobalFindAtom(up_atom) != 0)
			{
				if ( __msg_q( HWND_DESKTOP, restart_confirm ) ) _reboot( );
				status = NO_ERROR;
				break;
			}

			if ( dc_is_driver_installed() == FALSE )
			{
				status = ERROR_PRODUCT_UNINSTALLED;
				break;
			}

			if ( __msg_q( HWND_DESKTOP, L"Update DiskCryptor?" ) )
			{
				if ( (status = dc_update_driver()) == NO_ERROR && (status = _dc_upd_bootloader()) == NO_ERROR )
				{
					if ( __msg_q( HWND_DESKTOP, restart_confirm ) ) _reboot();
				}
			}
		}
		break;
	}
	return status;

}
Exemple #2
0
int WINAPI wWinMain(
		HINSTANCE hinst,
		HINSTANCE hprev,
		LPWSTR    cmd_line,
		int       cmd_show
		)
{
	int d_st;
	int resl;

	if (dc_is_old_runned() != 0) {
		return ST_INCOMPATIBLE;
	}

	/* open DC driver device */
	dc_open_device();
	/* get DC sriver status */
	d_st = dc_driver_status();
	resl = ST_ERROR;

	do
	{
		if (wcscmp(cmd_line, L"-setup") == 0)
		{
			if (d_st == ST_ERROR) {
				resl = dc_install_driver(NULL);
			} else
			{
				resl = dc_update_boot(-1);

				if ( (resl != ST_OK) && (resl != ST_BLDR_NOTINST) ) {
					break;
				}
				resl = dc_update_driver();
			}
			break;
		}

		if (wcscmp(cmd_line, L"-unins") == 0)
		{
			if (d_st == ST_ERROR) {
				resl = ST_ERROR; break;
			}
			resl = dc_remove_driver(); 
			break;
		}

		if (wcscmp(cmd_line, L"-unldr") == 0) {
			resl = dc_unset_mbr(-1);
			break;
		}

		if (wcscmp(cmd_line, L"-isboot") == 0) {
			ldr_config conf;
			resl = dc_get_mbr_config(-1, NULL, &conf);
			break;
		}		

		if (wcscmp(cmd_line, L"-isenc") == 0)
		{
			vol_inf info;
			u32     flags;
			wchar_t boot_dev[MAX_PATH];
			int     is_enc = 0;

			if (dc_open_device() != ST_OK) {
				resl = ST_ERROR; break;
			}

			if (dc_get_boot_device(boot_dev) != ST_OK) {
				boot_dev[0] = 0;
			}
	
			if (dc_first_volume(&info) == ST_OK)
			{
				do
				{
					flags = info.status.flags;

					if ( ((flags & F_SYSTEM) || 
						  (wcscmp(info.device, boot_dev) == 0)) && (flags & F_ENABLED) )
					{
						is_enc = 1;
					}
				} while (dc_next_volume(&info) == ST_OK);
			}

			dc_close_device();
			resl = is_enc != 0 ? ST_ENCRYPTED : ST_OK; break;
		}
	} while (0);

	return resl;
}