예제 #1
0
static void
SaveButtonClick (void)
{
  DmOpenRef openRef;
  UInt16 recIndex;
  MemHandle recH;
  Err err;

  if (EditorMidi.dbID == 0) {

    debugPrintf("dbID==0, create a new record in Palmano DB\n");
    /* create new record in palmano DB */
 
    err = getPalmanoDatabase(&openRef, dmModeReadWrite | dmModeExclusive);
    if (err != 0) {
      ErrAlert(err);
      return;
    }

    /* allocate new record in DB */
    recIndex = dmMaxRecordIndex;
    recH = DmNewRecord(openRef, &recIndex, 5); /* initial size is 5 bytes */
    ErrFatalDisplayIf(!recH, "SaveButtonClick(): can't get new record by index!");
  }
  else {
    /* replace old song in-place */

    openRef = DmOpenDatabase (EditorMidi.cardNo, EditorMidi.dbID,
			      dmModeReadWrite | dmModeExclusive);

    ErrFatalDisplayIf(!openRef, "SaveButtonClick(): "
		      "Can't open old song database for record");

    err = DmFindRecordByID(openRef, EditorMidi.uniqueRecID, &recIndex);

    ErrFatalDisplayIf(err, "Can't find record by ID");

    recH = DmGetRecord(openRef, recIndex);

    ErrFatalDisplayIf(!recH, "SaveButtonClick(): "
		      "Can't get old song record for writing");
  }

  // save midi to recH
  GetFieldTextToStr(EditorMidi.name, ID_EditorNameField, sndMidiNameLength);

  debugPrintf("SaveButtonClick(): smfutils_save(recH=%lx, name=%s\n",
	      recH, EditorMidi.name);
  smfutils_save(recH, EditorMidi.name, &notelist);
  debugPrintf("SaveButtonClick(): return from smfutils_save()\n");

  DmReleaseRecord (openRef, recIndex, 1);
  DmCloseDatabase (openRef);
  
  FrmGotoForm(ID_MainForm);
}
예제 #2
0
/* DESCRIPTION:  Get the application's database.  Open the database if it
 * exists, create it if neccessary.
 *
 * PARAMETERS:   *dbPP - pointer to a database ref (DmOpenRef) to be set
 *					  mode - how to open the database (dmModeReadWrite)
 *
 * RETURNED:     Err - zero if no error, else the error
 */
static Err getPalmanoDatabase (DmOpenRef *dbPP, UInt16 mode)
{
  Err error = 0;
  DmOpenRef dbP;

  *dbPP = NULL;
  
  // Find the application's data file.  If it doesn't exist create it.
  dbP = DmOpenDatabaseByTypeCreator (sysFileTMidi, pmnoCreatorDB, mode);

  if (!dbP) {
    debugPrintf("getPalmanoDatabase(): Can't open database, code %d\n",
		DmGetLastErr());
    error = DmCreateDatabase (0, "palmano", pmnoCreatorDB, sysFileTMidi, false);

    if (error) {
      debugPrintf("getPalmanoDatabase(): DmCreateDatabase exit code %d\n", error);
      ErrAlert(error);
      return error;
    }
    else
      debugPrintf("getPalmanoDatabase(): create DB ok\n");

    dbP = DmOpenDatabaseByTypeCreator(sysFileTMidi, pmnoCreatorDB, mode);
    if (!dbP) {
      debugPrintf("getPalmanoDatabase(): Can't open database after create, code %d\n",
		  DmGetLastErr());
      ErrAlert(DmGetLastErr());      
      return DmGetLastErr();
    } else
      debugPrintf("getPalmanoDatabase(): second open DB ok\n");


    // Set the backup bit.  This is to aid syncs with non Palm software.
    //    ToDoSetDBBackupBit(dbP);
		
  } else
    debugPrintf("getPalmanoDatabase(): open DB ok\n");


  *dbPP = dbP;
  return 0;
}
예제 #3
0
파일: KeyDAO.cpp 프로젝트: wzp85/myprotect
BOOL CKeyDao::CloseContainer(HCONTAINER hcontainer)
{
	int ret = 0;
	ret = GM_SKF_CloseContainer(hcontainer);
	if(ret)
	{
		ErrAlert("关闭容器失败",ret);
		return FALSE;
	}
	return TRUE;
}
예제 #4
0
파일: KeyDAO.cpp 프로젝트: wzp85/myprotect
BOOL CKeyDao::OpenContainer(HAPPLICATION hApplication,LPSTR szContainerName,HCONTAINER *phContainer)
{
	int ret = 0;
	ret = GM_SKF_OpenContainer(hApplication,szContainerName,phContainer);
	if(ret)
	{
		ErrAlert("打开容器失败",ret);
		return FALSE;
	}
	return TRUE;
}
예제 #5
0
파일: KeyDAO.cpp 프로젝트: wzp85/myprotect
BOOL CKeyDao::EnumContainer(HAPPLICATION hApplication,LPSTR szContainerName,ULONG *pulSize)
{
	int ret = 0;
	ret = GM_SKF_EnumContainer(hApplication,szContainerName,pulSize);
	if(ret)
	{
		ErrAlert("枚举容器失败",ret);
		return FALSE;
	}
	return TRUE;
}
예제 #6
0
파일: KeyDAO.cpp 프로젝트: wzp85/myprotect
BOOL CKeyDao::ChangePIN(HAPPLICATION hApplication,ULONG ulPINType,LPSTR szOldPin,LPSTR szNewPin,ULONG *pulRetryCount)
{
	int ret = 0;
	ret = GM_SKF_ChangePIN(hApplication,ulPINType,szOldPin,szNewPin,pulRetryCount);
	if(ret)
	{
		ErrAlert("修改PIN码失败",ret);
		return FALSE;
	}
	return TRUE;
}
예제 #7
0
파일: KeyDAO.cpp 프로젝트: wzp85/myprotect
BOOL CKeyDao::UnblockPIN(HAPPLICATION hApplication,LPSTR szAdminPIN,LPSTR szNewUserPIN,ULONG *pulRetryCount)
{
	int ret = 0;
	ret = GM_SKF_UnblockPIN(hApplication,szAdminPIN,szNewUserPIN,pulRetryCount);
	if(ret)
	{
		ErrAlert("解锁PIN失败",ret);
		return FALSE;
	}
	return TRUE;
}
예제 #8
0
파일: KeyDAO.cpp 프로젝트: wzp85/myprotect
BOOL CKeyDao::DevAuth(DEVHANDLE D_handle)
{
	int ret = 0;
	BYTE authCode[] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38};
	DEVINFO DevInfo={0};
	ret=GM_SKF_GetDevInfo ( D_handle, &DevInfo); //获取设备信息
	if(ret==SAR_FAIL)
	{
		ret = GM_SKF_SetLabel(D_handle,"1234567890abcdef");
		if(ret !=0 )
		{
			return FALSE;
		}
		ret = GM_SKF_GetDevInfo ( D_handle, &DevInfo);
	}
	//设备认证
	BYTE pucRandom[17]={0};
	ULONG ulRandomLen=8;
	ret = GM_SKF_GenRandom(D_handle,pucRandom,ulRandomLen);
	if(ret != 0)
	{			
		return FALSE;
	}
	ULONG ulKeyLen=16;
	HANDLE hKey;
		
	if(DevInfo.DevAuthAlgId == 0x0)
	{
		DevInfo.DevAuthAlgId = SGD_SSF33_ECB;
	}
	ret = GM_SKF_SetSymmKey(D_handle, authCode,DevInfo.DevAuthAlgId,&hKey);
	if(ret != 0)
	{			
		return FALSE;
	}
	//加密随机数
	BYTE pucAuthCode[128]={0};
	ULONG ulAuthCodeLen=128;

	memset(pucRandom+8,0x00,8);
		
	BLOCKCIPHERPARAM EncryptParam ;
	memset(&EncryptParam, 0, sizeof(BLOCKCIPHERPARAM)); //设备认证时
	ret = GM_SKF_EncryptInit(hKey,EncryptParam);
	if(ret != 0)
	{				
		return FALSE;
	}
		
	ret = GM_SKF_Encrypt( hKey,pucRandom,16,pucAuthCode,&ulAuthCodeLen);
	GM_SKF_CloseHandle(hKey);
	if(ret != 0)
	{				
		return FALSE;
	}
	//设备认证
	{
			
		ret = GM_SKF_DevAuth(D_handle,pucAuthCode,ulAuthCodeLen);
		//如果使用authCode认证出错,再使用authCode1认证	
		if(ret != 0)
		{	
			BYTE bRandom[0x10] = {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, bKey[0x40] = {0}, bData1[1024] = {0};
			memcpy(bKey, "1111111111111111", 16);
			ret = GM_SKF_GenRandom(D_handle, bRandom, 8);
			if(ret != 0)
			{			
			return FALSE;
			}
			ret = GM_SKF_SetSymmKey(D_handle, bKey,DevInfo.DevAuthAlgId,&hKey);
			if(ret != 0)
			{			
				return FALSE;
			}
			//加密随机数
				
			ret = GM_SKF_EncryptInit(hKey,EncryptParam);
			if(ret != 0)
			{				
				return FALSE;
			}
			ret = GM_SKF_Encrypt( hKey,bRandom,0x10,pucAuthCode,&ulAuthCodeLen);
			GM_SKF_CloseHandle(hKey);
			if(ret != 0)
			{				
				return FALSE;
			}
				
			ret = GM_SKF_DevAuth(D_handle,pucAuthCode,ulAuthCodeLen);
			if(ret != 0)
			{
				ErrAlert("设备认证失败",ret);
				return FALSE;
			}
				
		}
	}
	return TRUE;
}