Ejemplo n.º 1
0
bool ModuleSettings::SaveSettings() {

  if ( !IsDirty() ) {
    TRACE("Nothing to save as no change");
    return true;
  }
  CleanSettings();
  UpdateMd5();
  
  int n = sizeof(SettingData);
  uint8_t *p = (uint8_t*)(&data);

  EEPROM.begin(n);
  for (int i=0; i<n; i++) {
    delay(0);
    EEPROM.write(i,*p);
    p++;
  }

  bool bRvl = EEPROM.commit();
  if ( bRvl ) {
    TRACE("Settings saved succesfully.");
  }
  else {
    TRACE("Error saving settings.");
  }
  EEPROM.end();
  return bRvl;
}
Ejemplo n.º 2
0
void SaveMenuTree(HWND hdlg)
{
	int iBl=0,i=0,k=0;
	int iBtd=g_iButtonsCount;
	BOOL bDeleted=FALSE;
	char szMEntry[256]={'\0'};
	TCHAR strbuf[256];
	HTREEITEM hti=NULL;
	TVITEM tvi;

	g_iButtonsCount=TreeView_GetCount(hButtonsList);

	tvi.pszText = strbuf;
	tvi.cchTextMax = _countof(strbuf);
	tvi.mask=TVIF_HANDLE|TVIF_TEXT ;
	tvi.hItem=TreeView_GetRoot(hButtonsList);

	TreeView_GetItem(hButtonsList,&tvi);

	li_ZeroQuickList(QuickList);

	BalanceButtons(iBtd,g_iButtonsCount);

	while(ButtonsList[iBl])
	{
		SortedList * sl=NULL;
		ListData* ld=ButtonsList[iBl];

		if (!ld->sl) break;

		sl=ld->sl;

		if(ld->dwOPFlags&QMF_DELETNEEDED)
		{
			bDeleted=(ld->dwOPFlags&QMF_NEW)?FALSE:TRUE;
			if(bDeleted) CleanSettings(ld->dwPos,-1);
			DestroyButton(iBl);
			continue;
		}
		if(ld->ptszQValue!=ld->ptszOPQValue)	
		{
			if(ld->ptszQValue)
				mir_free(ld->ptszQValue);

			ld->ptszQValue=(ld->ptszOPQValue)?ld->ptszOPQValue:NULL;
		}

		if(ld->ptszButtonName)
			mir_free(ld->ptszButtonName);
		if(iBl>0)
			if(hti=TreeView_GetNextSibling(hButtonsList,hti?hti:tvi.hItem))
			{
				tvi.hItem=hti;
				TreeView_GetItem(hButtonsList,&tvi);
			}

			ld->ptszButtonName=mir_tstrdup(tvi.pszText);

			if(ld->ptszQValue)
			{
				mir_snprintf(szMEntry, _countof(szMEntry), "ButtonValue_%u", iBl);
				db_set_ts(NULL, PLGNAME,szMEntry,ld->ptszQValue);
			}


			if (ServiceExists(MS_BB_MODIFYBUTTON)&&((ld->dwOPFlags&QMF_NEW)||(ld->dwOPFlags&QMF_RENAMED)||bDeleted))
			{
				BBButton bb={0};
				bb.cbSize=sizeof(BBButton);
				bb.pszModuleName=PLGNAME;
				bb.dwButtonID=iBl;
				bb.ptszTooltip=ld->ptszButtonName;
				CallService(MS_BB_MODIFYBUTTON,0,(LPARAM)&bb);
			}	


			mir_snprintf(szMEntry, _countof(szMEntry), "ButtonName_%u", iBl);
			db_set_ts(NULL, PLGNAME,szMEntry,ld->ptszButtonName);

			ld->dwOPFlags=0;
			ld->dwPos=iBl;
			ld->bIsServName=ld->bIsOpServName;
			mir_snprintf(szMEntry, _countof(szMEntry), "RCEntryIsServiceName_%u", iBl);
			db_set_b(NULL, PLGNAME,szMEntry,ld->bIsServName);

			bDeleted=FALSE;

			qsort(sl->items,sl->realCount,sizeof(ButtonData *),sstSortButtons); 

			for ( i=0; i < sl->realCount; i++ ) {
				ButtonData * bd= (ButtonData *)sl->items[i];

				if(bd->dwOPFlags&QMF_DELETNEEDED){
					RemoveMenuEntryNode(sl, i--);
					continue;
				}
				bd->bIsServName=bd->bIsOpServName;
				bd->bInQMenu=bd->bOpInQMenu;
				bd->dwPos=bd->dwOPPos;
				bd->fEntryType=bd->fEntryOpType;
				bd->dwOPFlags=0;

				if(bd->pszName!=bd->pszOpName)
				{
					if(bd->pszName)
						mir_free(bd->pszName);
					bd->pszName=bd->pszOpName?bd->pszOpName:NULL;
				}

				if(bd->pszValue!=bd->pszOpValue)
				{
					if(bd->pszValue)
						mir_free(bd->pszValue);
					bd->pszValue=bd->pszOpValue?bd->pszOpValue:NULL;
				}
				if(bd->bInQMenu)
				{
					QuickData* qd = (QuickData *)mir_alloc(sizeof(QuickData));
					qd->dwPos=k++;
					qd->fEntryType=bd->fEntryType;
					qd->bIsService=bd->bIsServName;
					qd->ptszValue=bd->pszValue;
					qd->ptszValueName=bd->pszName;
					List_InsertPtr(QuickList,qd);
				}

				SaveModuleSettings(iBl,bd);
			}
			CleanSettings(iBl,sl->realCount);

			iBl++;
	}

	db_set_b(NULL, PLGNAME,"ButtonsCount", (BYTE)g_iButtonsCount);
}