Beispiel #1
0
LRESULT CWarningDlg::DlgProc(HWND c_hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch(uMsg)
  {
    case WM_INITDIALOG:
    {
		TCHAR szMessage[1024] = L"";
		swprintf(szMessage, NUMCHARS(szMessage), L"One or more of the alarm limits has been triggered\n\nCheck your Data Value parameters!!\n\nFailing Channel(s): \n%s", m_szYString);
		HWND hWndWarning = GetDlgItem(c_hWnd, IDC_WARNING1);
		SendMessage(hWndWarning, WM_SETTEXT, NUMCHARS(szMessage), (LPARAM)szMessage);
		MessageBeep(MB_OK);	//	Play a warning sound
		break;
    }
    case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
        case IDOK:
        {
          m_sfResult->fCancelled = false;
          EndDialog(c_hWnd,0);
          return TRUE;
        }
      }
      break;
    } // end WM_COMMAND
    case WM_CLOSE:
    {
      m_sfResult->fCancelled = true;
      EndDialog(c_hWnd,0);
      break;
    }
  }
  return FALSE;
}
void
TLoginDlg::LoadFromProps (void)
{
  TCHAR szValue[1024];
  BOOL bCertBased;

  m_props.Get (_T("DSN"), szValue, NUMCHARS (szValue));
  m_DSN.Text (szValue);

  if (m_props.Get (_T("PWDClearText"), szValue, NUMCHARS (szValue)))
    bCertBased = (_ttoi (szValue) == 3);
  else
    bCertBased = FALSE;

  m_props.Get (_T("UID"), szValue, NUMCHARS (szValue));
  if (ONLY_ONE_OF (bCertBased, ISFILENAME (szValue)))
    szValue[0] = 0;
  m_UID.Text (szValue);

  m_props.Get (_T("PWD"), szValue, NUMCHARS (szValue));
  m_PWD.Text (szValue);

  m_BROWSEUIDCERT.Show (bCertBased);
  m_UID.ReadOnly (bCertBased);
  LoadString (m_hInstance, bCertBased ? IDS_PKCS12LBL : IDS_UIDLBL,
      szValue, NUMCHARS (szValue));
  m_UIDLBL.Text (szValue);
}
BOOL APIENTRY
ConfigDSNW (
    HWND hWinParent,
    WORD fRequest,
    LPCTSTR lpszDriver,
    LPCTSTR lpszAttributes)
{
  TCHAR szNewDSN[MAX_DSN_LEN + 1];
  TCHAR szDSN[MAX_DSN_LEN + 1];
  TKVList props;
  TSetupDlg setupDlg (props);

  props.FromAttributes (lpszAttributes);
  if (props.Get (_T("DSN"), szDSN, NUMCHARS (szDSN)))
    {
      props.ReadODBCIni (szDSN, _virtuoso_tags);
      props.FromAttributes (lpszAttributes);
    }

  if (fRequest == ODBC_REMOVE_DSN)
    {
      SQLRemoveDSNFromIni (szDSN);
    }
  else if (fRequest == ODBC_CONFIG_DSN || fRequest == ODBC_ADD_DSN)
    {
      if (hWinParent)
        {
          setupDlg.m_bFileDSN = FALSE;
          if (setupDlg.RunModal (g_hInstance, IDD_CONFIGDSN, hWinParent) == IDOK)
	    {
	      if (props.Get (_T("DSN"), szNewDSN, NUMCHARS (szNewDSN)))
	        {
	          props.Undefine (_T("PWD"));
	          SQLWriteDSNToIni (szNewDSN, lpszDriver);
	          props.WriteODBCIni (szNewDSN, _virtuoso_tags);

	          /* If the DSN has changed, delete the old one */
	          if (fRequest == ODBC_CONFIG_DSN && _tcsicmp (szDSN, szNewDSN))
		    SQLRemoveDSNFromIni (szDSN);
	        }
	    }
        }
      else
        {
	  if (props.Get (_T("DSN"), szNewDSN, NUMCHARS (szNewDSN)))
	    {
	       props.Undefine (_T("PWD"));
	       SQLWriteDSNToIni (szNewDSN, lpszDriver);
	       props.WriteODBCIni (szNewDSN, _virtuoso_tags);

	       /* If the DSN has changed, delete the old one */
	       if (fRequest == ODBC_CONFIG_DSN && _tcsicmp (szDSN, szNewDSN))
	          SQLRemoveDSNFromIni (szDSN);
	    }
        }
    }

  return TRUE;
}
void CDlgTimingScoring::ClearHotLaps()
{
	for (int x = 0; x < 50; x++)
	{
		swprintf(m_ScoringData[x].lstPos, NUMCHARS(m_ScoringData[x].lstPos), L"");
		swprintf(m_ScoringData[x].lstRaceName, NUMCHARS(m_ScoringData[x].lstRaceName), L"");
		swprintf(m_ScoringData[x].lstComment, NUMCHARS(m_ScoringData[x].lstComment), L"");
		swprintf(m_ScoringData[x].lstLapTimes, NUMCHARS(m_ScoringData[x].lstLapTimes), L"");
	}
}
void
TSetupDlg::FillAuthMethods (void)
{
  LPTSTR szValue;
  TCHAR szText[256];
  int iIndex;
  int i;

  /* Get current text */
  szValue = m_AUTHMETHOD.Text ();
  m_AUTHMETHOD.Clear ();
  for (i = 0; i < 3; i++)
    {
      LoadString (m_hInstance, IDS_AUTHMETHOD1 + i, szText, NUMCHARS (szText));
      m_AUTHMETHOD.AddString (szText);
    }

  BOOL bOn;
  if ((bOn = m_USESSL.Checked ()))
    {
      LoadString (m_hInstance, IDS_AUTHMETHOD4, szText, NUMCHARS (szText));
      m_AUTHMETHOD.AddString (szText);
    }
  m_USESERVERCERT.Show (bOn);
  m_SERVERCERTLBL.Show (bOn);
  m_SERVERCERT.Show (bOn);
  m_BROWSESERVERCERT.Show (bOn);

  /* Set + select old value */
  m_AUTHMETHOD.Text (szValue);
  iIndex = m_AUTHMETHOD.FindExact (szValue);
  if (iIndex == CB_ERR)
    {
      switch (m_dwClearText)
	{
	case 1: /* clear text */
	  iIndex = AUTHMETHOD_CLEAR;
	  break;
	case 2: /* encrypted */
	  iIndex = AUTHMETHOD_ENCRYPTED;
	  break;
	case 3: /* cert. based */
	  iIndex = AUTHMETHOD_PKCS12;
	  break;
	default:
	  iIndex = AUTHMETHOD_CHALLENGE;
	  break;
	};
    }
  m_AUTHMETHOD.CurSel (iIndex);
  SetAuthMethod ();
}
Beispiel #6
0
LRESULT CRaceRerunDlg::DlgProc(HWND c_hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch(uMsg)
  {
    case WM_INITDIALOG:
    {
		TCHAR szText[MAX_PATH];
		swprintf(szText, NUMCHARS(szText), L"%i", m_sfResult->iStart);
		SetDlgItemText(c_hWnd, IDC_RACE_START, szText);

		swprintf(szText, NUMCHARS(szText), L"%i", m_sfResult->iEnd);
		SetDlgItemText(c_hWnd, IDC_RACE_END, szText);
		m_sfResult->iEnd = _wtoi(szText);
		break;
    }
    case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
        case IDOK:
        {
          m_sfResult->fCancelled = false;
		  TCHAR szText[MAX_PATH];
		  GetDlgItemText(c_hWnd, IDC_RACE_START, szText, NUMCHARS(szText));
		  m_sfResult->iStart = _wtoi(szText);

		  GetDlgItemText(c_hWnd, IDC_RACE_END, szText, NUMCHARS(szText));
		  m_sfResult->iEnd = _wtoi(szText);
          EndDialog(c_hWnd,0);
          return TRUE;
        }
        case IDCANCEL:
		{
			m_sfResult->fCancelled = true;
			EndDialog(c_hWnd,0);
			return TRUE;
		}
      }
      break;
    } // end WM_COMMAND
    case WM_CLOSE:
    {
      m_sfResult->fCancelled = true;
      EndDialog(c_hWnd,0);
      break;
    }
  }
  return FALSE;
}
 virtual const vector<TimePoint2D> GetPoints() const override
 {
   vector<TimePoint2D> lstPoints;
   bool fSuccess = false;
   // they're asking for points.  This is where stuff gets expensive
   // now we need to get all the datapoints for this lap (data channels will come later)
   TCHAR szQuery[MAX_PATH];
   _snwprintf(szQuery, NUMCHARS(szQuery), L"select points.x,points.y,points.time,points.velocity from points where points.lapid = %d", m_iLapId);
   CSfArtSQLiteQuery sfPointQuery(m_sfDB);
   if(sfPointQuery.Init(szQuery))
   {
     while(sfPointQuery.Next())
     {
       TimePoint2D pt;
       fSuccess &= sfPointQuery.GetCol(0,&pt.flX);
       fSuccess &= sfPointQuery.GetCol(1,&pt.flY);
       fSuccess &= sfPointQuery.GetCol(2,&pt.iTime);
       fSuccess &= sfPointQuery.GetCol(3,&pt.flVelocity);
       pt.flSum = pt.flX + pt.flY;
       DASSERT(pt.IsValid());
       if(pt.IsValid())
       {
         lstPoints.push_back(pt);
       }
     }
   }
   return lstPoints;
 }
void
TSetupDlg::SetAuthMethod (void)
{
  TCHAR szText[32];
  BOOL bCertBased;
  PTSTR szUID;

  bCertBased = (m_AUTHMETHOD.CurSel () == AUTHMETHOD_PKCS12) ? 1 : 0;

  /* change label from 'Login ID' <--> 'PKCS12 File' */
  LoadString (m_hInstance, bCertBased ? IDS_PKCS12LBL : IDS_UIDLBL,
      szText, NUMCHARS (szText));
  m_UIDLBL.Text (szText);

  /* Re-limit the length for the UID edit control */
  SendMessage (m_UID.m_hCtl, EM_LIMITTEXT,
      bCertBased ? MAX_PATH : MAX_UID_LEN, 0);

  /* Clear UID if authmethod changed from certbased <--> normal */
  szUID = m_UID.Text ();
  if (ONLY_ONE_OF (bCertBased, ISFILENAME (szUID)))
    {
      m_UID.Text (_T(""));
      m_PWD.Text (_T(""));
    }
  m_UID.ReadOnly (bCertBased);

  /* Show browse button for PKCS12 File authentication */
  m_BROWSEUIDCERT.Show (bCertBased);
}
Beispiel #9
0
int __cdecl main()
{
   HRESULT hr = App_Early_Initialize();
   if (SUCCEEDED(hr))
      {
      hr = App_ExecuteCommandLine (GetCommandLine(), TRUE);
      if (FAILED(hr))
         g_app.fUsage = TRUE;
      }

   if (g_app.fShowLogo || g_app.fUsage)
      {
      LPCTSTR pszAppName = _pszModuleName;
      bprintfl("%s version 1.0.0 Built " __DATE__ __TIME__, pszAppName);
      }

   if (g_app.fUsage)
      {
      LPCTSTR pszAppName = _pszModuleName;

      bprintf("\nusage: %s [/? | /HELP] [@{argfile}] [args] <dir>\n\n", pszAppName);
      bprintf("  remove directory <dir>, taking ownership and removing\n");
      bprintf("  ACLs as necessary. Where [args] is one or more of\n\n");

      for (int ii = 0; ii < NUMELMS(g_aAppCommands); ++ii)
         {
         CMDTABLE * pCmd = &g_aAppCommands[ii];
         if ( ! pCmd->pszName)
            break;
         LPCTSTR pszCmd = pCmd->pszName;
         TCHAR szCmd[128];
         if (pCmd->cmd.cParams > 0)
            {
            StrCopy(szCmd, pCmd->pszName, NUMCHARS(szCmd));
            int cch = StrLen(szCmd);
            szCmd[cch++] = ':';
            StrCopy(szCmd+cch, pCmd->pszArgType, NUMCHARS(szCmd)-cch);
            pszCmd = szCmd;
            }
         bprintf("  /%-16s", pszCmd);
         bprintf("  %s\n", pCmd->pszUsage);
         }
      }

   App_Cleanup(SUCCEEDED(hr));
   return (int)hr;
}
Beispiel #10
0
void CSQLiteLapDB::GetComments(int iLapId, vector<wstring>& lstComments) const
{
  CSfArtSQLiteQuery sfQuery(m_sfDB);
  TCHAR szQuery[MAX_PATH];
  _snwprintf(szQuery, NUMCHARS(szQuery), L"select extras.comment from extras where extras.lapid = %d", iLapId);
  if(sfQuery.Init(szQuery))
  {
    while(sfQuery.Next())
    {
      TCHAR szComment[500];
      if(sfQuery.GetCol(0,szComment, NUMCHARS(szComment)))
      {
        lstComments.push_back(szComment);
      }
    }
  }
}
const IDataChannel* CSQLiteLapDB::GetDataChannel(int iLapId, DATA_CHANNEL eChannel) const
{
  AutoLeaveCS _cs(&m_cs);
  if(eChannel == DATA_CHANNEL_VELOCITY)
  {
    // since velocity is stored as part of the points table, it is a bit different than the normal data channels
    CSfArtSQLiteQuery sfQuery(m_sfDB);
    TCHAR szQuery[MAX_PATH];
    _snwprintf(szQuery, NUMCHARS(szQuery), L"select points.time, points.velocity from points where lapid=%d", iLapId);
    if(sfQuery.Init(szQuery))
    {
      IDataChannel* pChannel = AllocateDataChannel();
      pChannel->Init(iLapId,DATA_CHANNEL_VELOCITY);
      while(sfQuery.Next())
      {
        int iTime = 0;
        double dVel = 0;
        if(sfQuery.GetCol(0,&iTime) && sfQuery.GetCol(1,&dVel))
        {
          pChannel->AddPoint(iTime, dVel);
        }
      }
      pChannel->Lock();
      return pChannel;
    }
  }
  else
  {
    CSfArtSQLiteQuery sfQuery(m_sfDB);
    TCHAR szQuery[MAX_PATH];
    _snwprintf(szQuery, NUMCHARS(szQuery), L"select channels._id, channels.lapid, channels.channeltype from channels where channels.lapid = %d and channels.channeltype=%d", iLapId, eChannel);
    if(sfQuery.Init(szQuery))
    {
      if(sfQuery.Next())
      {
        IDataChannel* pChannel = AllocateDataChannel();
        pChannel->Load(m_sfDB,sfQuery,true);
        // warning: massive memory leaks here
        return pChannel;
      }
    }
  }
  return NULL;
}
vector<RACEDATA> CSQLiteLapDB::GetRaces()
{
  AutoLeaveCS _cs(&m_cs);
  vector<RACEDATA> lstRaces;
  CSfArtSQLiteQuery sfQuery(m_sfDB);
  TCHAR szQuery[MAX_PATH];
  _snwprintf(szQuery, NUMCHARS(szQuery), L"select races.name,races.date,count(laps._id),races._id from races,laps where laps.raceid=races._id group by races._id");

  if(sfQuery.Init(szQuery))
  {
    while(sfQuery.Next())
    {
      RACEDATA raceData;
      TCHAR szData[1000];
      if(sfQuery.GetCol(0,szData,NUMCHARS(szData)))
      {
        raceData.strName = szData;
        int iRaceDate = 0;
        if(sfQuery.GetCol(1,&iRaceDate))
        {
          raceData.unixtime = iRaceDate;
        }
        int cLaps = 0;
        if(sfQuery.GetCol(2,&cLaps))
        {
          raceData.laps = cLaps;
        }
        int iRaceId = 0;
        if(sfQuery.GetCol(3,&iRaceId))
        {
          raceData.raceId = iRaceId;
        }
        lstRaces.push_back(raceData);
      }
    }
  }
  return lstRaces;
}
Beispiel #13
0
void
TKVList::ReadODBCIni (LPCTSTR section, LPCTSTR names)
{
  TCHAR value[512];
  LPCTSTR key;

  for (key = names; *key; key += _tcslen (key) + 1)
    {
      SQLGetPrivateProfileString (section, key, _T(" "), value,
	  NUMCHARS (value), _T("odbc.ini"));
      if (_tcscmp (value, _T(" ")))
	Define (key, value);
    }
}
void
TODBCConn::ShowStmtError (HINSTANCE hInstance, HWND hParentWnd)
{
  SQLSMALLINT wSize;
  SQLError (
      m_hEnv,
      m_hDbc,
      SQL_NULL_HSTMT,
      (_SQLCHAR *) m_szSQLState,
      NULL,
      (_SQLCHAR *) m_szSQLMessage,
      NUMCHARS (m_szSQLMessage),
      &wSize);
  ShowError (hInstance, hParentWnd);
}
Beispiel #15
0
static void PrintSidName(PSID psid, BPRINT_BUFFER & bp)
{
   TCHAR szDomain[32]; // max domain name is actually 15
   DWORD cchDomain = NUMCHARS(szDomain);
   TCHAR szName[MAX_PATH];
   DWORD cchName = NUMCHARS(szName);
   SID_NAME_USE snu;

   szDomain[0] = szName[0] = 0;
   if ( ! LookupAccountSid(NULL, psid, szName, &cchName, szDomain, &cchDomain, &snu))
      {
      if (GetLastError() != ERROR_NONE_MAPPED)
         ReportError(GetLastError(), "LookupAccountSid");
      }
   else
      {
      if (szDomain[0])
         {
         bprint(bp, szDomain);
         bprint(bp, "\\");
         }
      bprint(bp, szName);
      }
}
  virtual bool Load(CSfArtSQLiteDB& db, StartFinish* rgSF, CSfArtSQLiteQuery& line) override
  {
    bool fSuccess = true;
    fSuccess &= (line.GetCol(0, &m_iLapId));
    fSuccess &= (line.GetCol(1, &m_flLapTime));
    fSuccess &= (line.GetCol(2, &m_iStartTime));

    TCHAR szComment[200];
    szComment[0] = 0;
    fSuccess &= (line.GetCol(3, szComment, NUMCHARS(szComment)));
    m_strComment = wstring(szComment);

    memcpy(this->m_rgSF, rgSF, sizeof(this->m_rgSF));

    return fSuccess;
  }
Beispiel #17
0
  void WriteChannelHeaders(wofstream& out, const vector<const ILap*>& lstLaps, map<DATA_CHANNEL, const IDataChannel*>& mapData)
  {
    // if you update this function, update the dashware.xml file too!
    out<<L"Lap,Time,x,y";

    // column headers
    for(map<DATA_CHANNEL, const IDataChannel*>::iterator i = begin(mapData); i != end(mapData); i++)
    {
      TCHAR szDataChannelName[MAX_PATH];
      const DATA_CHANNEL eChannel = i->first;
      GetDataChannelName(eChannel, szDataChannelName, NUMCHARS(szDataChannelName));
      out<<","<<szDataChannelName;
    }
    out<<","<<endl;

  }
Beispiel #18
0
const ILap* CSQLiteLapDB::GetLap(int iLapId)
{
  CSfArtSQLiteQuery sfQuery(m_sfDB);
  TCHAR szQuery[MAX_PATH];
  _snwprintf(szQuery, NUMCHARS(szQuery), L"Select laps._id,laps.laptime, laps.unixtime from laps where laps._id = %d", iLapId);
  if(sfQuery.Init(szQuery))
  {
    if(sfQuery.Next())
    {
      CSQLiteLap* pLap = (CSQLiteLap*)AllocateLap(false);
      pLap->Load(m_sfDB,m_rgSF,sfQuery);

      return pLap;
    }
  }
  return NULL;
}
BOOL
TSetupDlg::ODBCConnect (TODBCConn &conn)
{
  TCHAR szDSN[MAX_SERVER_LEN + MAX_PATH + MAX_PWD_LEN + 100];
  LPCTSTR szHost;

  /* Make sure we have resolved the ZC name,
   * or that the user type <host>:<port> in the server name window
   */
  if ((szHost = m_SERVER.GetHost ()) == NULL)
    {
      conn.m_szSQLState[0] = 0;
      LoadString (m_hInstance,
	  IDS_ZCUNRESOLVED,
	  conn.m_szSQLMessage, NUMCHARS (conn.m_szSQLMessage));
      conn.ShowError (m_hInstance, m_hWnd);
      ChangePage (0);
      return FALSE;
    }

  if (m_AUTHMETHOD.CurSel () == AUTHMETHOD_PKCS12)
    {
      _stprintf (szDSN, _T("HOST=%s;UID=;ENCRYPT=%s;PWD=%s;SERVERCERT=%s"),
	  szHost,
	  m_UID.Text (),
	  m_PWD.Text (),
	  m_USESERVERCERT.Checked () ? m_SERVERCERT.Text () : _T(""));
    }
  else
    {
      _stprintf (szDSN, _T("HOST=%s;UID=%s;PWD=%s"),
	  szHost,
	  m_UID.Text (),
	  m_PWD.Text ());
      if (m_USESSL.Checked ())
	_tcscat (szDSN, _T(";ENCRYPT=1"));
    }

  if (!conn.Connect (m_hWnd, szDSN))
    {
      conn.ShowError (m_hInstance, m_hWnd);
      return FALSE;
    }

  return TRUE;
}
Beispiel #20
0
void
TKVList::ReadFileDSN (LPCTSTR filename, LPCTSTR names)
{
  TCHAR value[512];
  LPCTSTR key;
  WORD len;

  for (key = names; *key; key += _tcslen (key) + 1)
    {
      value[0] = 0;
      if (SQLReadFileDSN (filename, _T("ODBC"), key, value,
	  NUMCHARS (value), &len))
	{
	  Define (key, value);
	}
    }
}
void
TSetupDlg::FillIsolationLevels (void)
{
  LPTSTR szValue;
  TCHAR szText[256];
  int i, iIndex;

  szValue = m_DEFAULTIL.Text ();
  m_DEFAULTIL.Clear ();
  for (i =0; i < 4; i++)
    {
      LoadString (m_hInstance, IDS_ISOLATIONLEVEL1 + i, szText, NUMCHARS (szText));
      m_DEFAULTIL.AddString (szText);
    }
  m_DEFAULTIL.Text (szValue);
  iIndex = m_DEFAULTIL.FindExact (szValue);
  if (iIndex != CB_ERR)
    m_DEFAULTIL.CurSel (iIndex);
}
Beispiel #22
0
set<DATA_CHANNEL> CSQLiteLapDB::GetAvailableChannels(int iLapId) const
{
  set<DATA_CHANNEL> setRet;

  CSfArtSQLiteQuery sfQuery(m_sfDB);
  TCHAR szQuery[MAX_PATH];
  _snwprintf(szQuery, NUMCHARS(szQuery), L"select channels.channeltype from channels where channels.lapid = %d", iLapId);
  if(sfQuery.Init(szQuery))
  {
    while(sfQuery.Next())
    {
      DATA_CHANNEL eType;
      if(sfQuery.GetCol(0,(int*)&eType))
      {
        setRet.insert(eType);
      }
    }
  }
  return setRet;
}
int CSQLiteLapDB::GetLapCount(int iRaceId) const
{
  AutoLeaveCS _cs(&m_cs);
  CSfArtSQLiteQuery sfQuery(m_sfDB);
  TCHAR szQuery[MAX_PATH];
  _snwprintf(szQuery, NUMCHARS(szQuery), L"select count(laps._id) from races,laps where races._id = %d and laps.raceid=races._id group by races._id", iRaceId);

  if(sfQuery.Init(szQuery))
  {
    while(sfQuery.Next())
    {
      int cLaps = 0;
      if(sfQuery.GetCol(0,&cLaps))
      {
        return cLaps;
      }
    }
  }
  return 0;
}
Beispiel #24
0
vector<const ILap*> CSQLiteLapDB::GetLaps(int iRaceId)
{
  vector<const ILap*> lstLaps;
  // gotta load all the laps that are in the DB, but we don't want to fully load them, just their laptimes and other directly lap-related data
  CSfArtSQLiteQuery sfQuery(m_sfDB);
  TCHAR szQuery[MAX_PATH];
  _snwprintf(szQuery, NUMCHARS(szQuery), L"Select laps._id,laps.laptime, laps.unixtime,extras.comment from laps left join extras on extras.lapid = laps._id where laps.raceid=%d", iRaceId);
  if(sfQuery.Init(szQuery))
  {
    while(sfQuery.Next())
    {
      CSQLiteLap* pLap = (CSQLiteLap*)AllocateLap(false);
      pLap->Load(m_sfDB,m_rgSF,sfQuery);
      if(pLap->IsValid())
      {
        lstLaps.push_back(pLap);
      }
    }
  }
  return lstLaps;
}
LRESULT CRaceSelectEditDlg::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch(uMsg)
  {
    case WM_INITDIALOG:
    {
      vector<wstring> lstCols;
      vector<int> lstWidths;
      lstCols.push_back(L"Date");
      lstCols.push_back(L"Race Name");
      lstCols.push_back(L"Laps");
      lstWidths.push_back(75);
      lstWidths.push_back(160);
      lstWidths.push_back(40);
      sfListBox.Init(GetDlgItem(hWnd,IDC_RACE),lstCols,lstWidths);

      // gotta set up the list
      vector<RACEDATA> lstRaces = m_pLapDB->GetRaces();
      
      for(int x = 0;x < lstRaces.size(); x++)
      {
        vector<wstring> lstCols;

        SYSTEMTIME stStart = SecondsSince1970ToSYSTEMTIME(lstRaces[x].unixtime);
        TCHAR szDate[100];
        _snwprintf(szDate,NUMCHARS(szDate),L"%d/%d/%4d",stStart.wMonth,stStart.wDay,stStart.wYear);
        lstCols.push_back(szDate);
              
        lstCols.push_back(lstRaces[x].strName.c_str());

        TCHAR szTemp[MAX_PATH];
        _snwprintf(szTemp, NUMCHARS(szTemp), L"%d",lstRaces[x].laps);
        lstCols.push_back(szTemp);

        sfListBox.AddStrings(lstCols,lstRaces[x].raceId);
      }

      break;
    }
    case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
        case IDOK:
        {
          set<LPARAM> set = sfListBox.GetSelectedItemsData();
          if(set.size() == 1)
          {
			MessageBox(NULL,L"Only 1 race session selected\n\nNo changes were made",L"", MB_OK);
            m_pResults->iRaceId = *set.begin();
            m_pResults->fCancelled = false;
            EndDialog(hWnd,0);
          }
          else
          {
              if(set.size() >= 1)
              {
					MessageBox(NULL,L"No changes were made",L"", MB_OK);
					m_pResults->iRaceId = *set.begin();
					m_pResults->fCancelled = false;
					EndDialog(hWnd,0);
              }
          }
          return TRUE;
        }
        case IDC_RACEEDIT_MERGE:
        {
		  //	Let's make sure that the user really wants to do this.
		  RACEEDITCONFIRM_RESULT sfResult;
		  CRaceEditConfirmDlg dlgRaceEditConfirm(&sfResult);
		  ArtShowDialog<IDD_RACEEDITCONFIRM>(&dlgRaceEditConfirm);
		  if(!sfResult.fCancelled)
		  {
			  // Okay they are serious and really want to merge these race sessions
			  set<LPARAM> setSelected = sfListBox.GetSelectedItemsData();
			  if(setSelected.size() == 1)
			  {
				//	Do nothing, only 1 race session chosen
				MessageBox(NULL,L"Only 1 race session selected\n\nNo changes were made",L"", MB_OK);
			  }
			  else if(setSelected.size() >= 1)
			  {
				//   Need to find all Race Sessions selected, and then merge them into a single RaceID
				int iFirstRaceId = -1;
				for(set<LPARAM>::const_iterator i = setSelected.begin(); i != setSelected.end(); i++)
				{
				  if(iFirstRaceId == -1)
				  {
					iFirstRaceId = *i;
					continue; // don't need to merge this lap with itself
				  }
				  else
				  {
					bool RaceCheck = g_pLapDB->MergeLaps(iFirstRaceId, *i); // merges the current race with the first race.
					if (RaceCheck == false)
					{
					  MessageBox(NULL,L"Race session merging failed!\n\nPost on Wifilapper Forum about this issue",L"", MB_OK);
					}
				  }
				}
				//	Finally, let's load this new combined Race Session as current and close the dialog box.
				if (iFirstRaceId != -1) m_pResults->iRaceId = iFirstRaceId;
				m_pResults->fCancelled = false;
				EndDialog(hWnd,0);
			  }
			  return TRUE;
		  }
          m_pResults->fCancelled = true;	//	User cancelled the operation at the warning/confirm screen
          EndDialog(hWnd,0);
		  return TRUE;
        }
        case IDC_RACEEDIT_RENAME:
        {
		  //	Let's make sure that the user really wants to do this.
		  RENAMEDLG_RESULT sfResult;
		  CRenameDlg dlgRaceRename(&sfResult);
		  ArtShowDialog<IDD_RACENAMECHANGE>(&dlgRaceRename);
		  if(!sfResult.fCancelled)
		  {
			  // Okay they are serious and really want to rename these race sessions
			  set<LPARAM> setSelected = sfListBox.GetSelectedItemsData();
			  if(setSelected.size() == 0)
			  {
				//	Do nothing, no race sessions chosen
				MessageBox(NULL,L"No race sessions selected\n\nNo changes were made",L"", MB_OK);
			  }
			  else if(setSelected.size() >= 1)
			  {
				//	The new name for the chosen race sessions is contained in m_pResults->szName				
				//   Need to find all Race Sessions selected, and then reanme them with szName
				int iFirstRaceId = -1;
				for(set<LPARAM>::const_iterator i = setSelected.begin(); i != setSelected.end(); i++)
				{
					bool RaceCheck = g_pLapDB->RenameLaps(sfResult.szName, *i); // renames the current race with the inputed string.
					if (RaceCheck == false)
					{
					  MessageBox(NULL,L"Race session renaming failed!\n\nPost on Wifilapper Forum about this issue",L"", MB_OK);
					}
				}
				//	Close the dialog. User will have to reopen it to see the changed names
				m_pResults->iRaceId = *setSelected.begin();
				m_pResults->fCancelled = false;
				EndDialog(hWnd,0);
			  }
			  return TRUE;
		  }
	      m_pResults->fCancelled = true;	//	User cancelled the operation at the warning/confirm screen
	      EndDialog(hWnd,0);
		  return TRUE;
        }
        case IDCANCEL:
		{
          m_pResults->fCancelled = true;
          EndDialog(hWnd,0);
          return TRUE;
		}
      }
      break;
    } // end WM_COMMAND
    case WM_CLOSE:
    {
      m_pResults->fCancelled = true;
      EndDialog(hWnd,0);
      break;
    }
  }
  return FALSE;
}
Beispiel #26
0
HRESULT App_CookArgList (
   HCMDLIST * phlst,
   LPCTSTR    aArgs[],
   UINT       ixFirst,  // first arg to execute
   UINT       cArgs)    // count of args to execute
{
   HRESULT    hr = S_FALSE; // there were no args...
   TCHAR      szTempArg[64]; // temp if we need to copy and arg

   HCMDLIST   hlst;

   *phlst = NULL;
   hr = Vector_Create(&hlst, cArgs, -1);
   if (FAILED(hr))
      return hr;

   // look at args, parsing switches and building up the array of filename pointers
   //
   UINT ixLast = (ixFirst + cArgs);
   for (UINT ii = ixFirst; ii < ixLast; ++ii)
      {
      LPCTSTR pszArg = aArgs[ii];
      if ( ! pszArg)
         break;

      // assume a file open command.
      //
      hr = S_OK;
      CMDSWITCH cmd = {APP_CMD_PATH, 0, 1, NULL};

      // if the first character of the arg is an '@', what follows should be a command file.
      //
      if (pszArg[0] == '@')
         {
         // command will be an argfile command
         //
         cmd.idCmd     = APP_CMD_ARGFILE;
         cmd.cParams   = 1;    // on arg needed
         cmd.pszParams = NULL; // no default

         // if next character is not a 0, it must be the filename
         // otherwise, suck up the next token and use it as the filename.
         //
         pszArg = StrCharNext (pszArg); // skip '@'
         if (0 != pszArg[0])
            {
            cmd.pszParams = pszArg;
            }
         else if (ii+1 < ixLast) // next pszArg belongs to us..
            {
            LPCTSTR pszT = aArgs[ii+1];
            if ('-' != pszT[0] && '/' != pszT[0])
               {
               cmd.pszParams = pszT;
               ++ii;  // advance the loop counter.
               }
            }
         }
      else if ('-' == pszArg[0] || '/' == pszArg[0])
         {
         pszArg = StrCharNext (pszArg);
         if (0 == pszArg[0])
            {
            hr = E_INVALIDARG;
            goto bail;
            }

         // look for a ':' in the arg, and
         //
         LPCTSTR psz = StrCharNext(pszArg);
         LPCTSTR pszParam = NULL;
         while (0 != psz[0])
            {
            // if the arg contains a colon, set pszParam to point to it
            // and extract the stuff before the colon as the actual arg.
            //
            if (':' == psz[0])
               {
               pszParam = StrCharNext (psz);
               UINT cch = (UINT)(((LPARAM)psz - (LPARAM)pszArg) / NUMBYTES(TCHAR));
               StrCopyN (szTempArg, NUMCHARS(szTempArg), pszArg, cch + 1);
               DASSERT(0 == szTempArg[min(NUMCHARS(szTempArg)-1, cch)]);
               pszArg = szTempArg;
               break;
               }

            psz = StrCharNext(psz);
            }

         // lookup the argment
         //
         if ( ! App_LookupCmdLineArg (g_aAppCommands, pszArg, &cmd))
            {
            bprintfl("%s is not a valid argument", pszArg);
            hr = E_INVALIDARG;
            goto bail;
            }

         if (pszParam)
            {
            if (cmd.cParams < 1)
               {
               // if we have a param, but the arg doesn't take any, bail.
               //
               bprintfl("the %s argument is does not take parameters", pszArg);
               hr = E_INVALIDARG;
               goto bail;
               }

            cmd.pszParams = pszParam;
            }
         else
            {
            // if the command needs args, but none have been found so
            // far, try sucking up the next token in the command line
            //
            if (cmd.cParams > 0 && NULL == cmd.pszParams)
               {
               if (ii+1 < ixLast) // next pszArg belongs to us..
                  {
                  LPCTSTR pszT = aArgs[ii+1];
                  if ('-' != pszT[0] && '/' != pszT[0])
                     {
                     cmd.pszParams = pszT;
                     ++ii;  // advance the loop counter.
                     }
                  }
               }
            }
         }
      else
         {
         // not a switch, this is an implied file-open command
         //
         cmd.pszParams = pszArg;
         }

      // if the command needs an arg, but we dont have one.
      // the command line is in error.
      //
      if ((cmd.cParams > 0) && (NULL == cmd.pszParams))
         {
         bprintfl("the %s argument requires parameters", pszArg);
         g_app.fUsage = true;
         hr = E_INVALIDARG;
         goto bail;
         }

      // append the command.
      //
      Vector_AppendItem(hlst, cmd);
      }

   // return the command list
   //
   *phlst = hlst;

bail:
   if (FAILED(hr) || Vector_GetCountSafe(hlst) < 1)
      {
      *phlst = NULL;
      if (hlst)
         Vector_Delete (hlst);
      }
   return hr;
}
Beispiel #27
0
  HRESULT SaveToDashware(LPCTSTR lpszFilename, const vector<const ILap*>& lstLaps)
  {
    if(lstLaps.size() <= 0) return E_FAIL;

    vector<const ILap*> lstSortedLaps = lstLaps;
    sort(begin(lstSortedLaps),end(lstSortedLaps),SortLapsByTime);

    wofstream out;
    out.open(lpszFilename);

    map<DATA_CHANNEL,const IDataChannel*> mapChannels;

    for(int ixLap = 0;ixLap < lstLaps.size(); ixLap++)
    {
      for(int y = 0; y < DATA_CHANNEL_COUNT; y++)
      {
        const IDataChannel* pChannel = g_pLapDB->GetDataChannel(lstLaps[ixLap]->GetLapId(),(DATA_CHANNEL)y);
        DASSERT(pChannel->IsLocked() && pChannel->IsValid());
        if(pChannel && pChannel->IsLocked() && pChannel->IsValid())
        {
          mapChannels[(DATA_CHANNEL)y] = pChannel;
        }
        else
        {
          DASSERT(FALSE);
        }
      }
    }

    WriteChannelHeaders(out, lstSortedLaps, mapChannels);


    int msLastLine = 0;
    float flStartTime = 0; // start time in seconds;
    for(int ixLap = 0; ixLap < lstSortedLaps.size(); ixLap++)
    {
      const ILap* pLap = lstSortedLaps[ixLap];
      int msStartTime = INT_MAX; // start time and end time for this lap (gotten by looking at start and end time for data channels)
      int msEndTime = -INT_MAX;

      for(int y = 0; y < DATA_CHANNEL_COUNT; y++)
      {
        const IDataChannel* pChannel = g_pLapDB->GetDataChannel(pLap->GetLapId(),(DATA_CHANNEL)y);
        DASSERT(pChannel->IsLocked() && pChannel->IsValid() && pChannel->GetChannelType() == (DATA_CHANNEL)y);
        if(pChannel && pChannel->IsLocked() && pChannel->IsValid())
        {
          mapChannels[(DATA_CHANNEL)y] = pChannel;
        }
        else
        {
          DASSERT(FALSE);
        }
      }

      for(map<DATA_CHANNEL, const IDataChannel*>::iterator i = begin(mapChannels); i != end(mapChannels); i++)
      {
        const IDataChannel* pDC = mapChannels[i->first];
        if(pDC)
        {
          msStartTime = min(pDC->GetStartTimeMs(),msStartTime);
          msEndTime = max(pDC->GetEndTimeMs(),msEndTime);
        }
      }
      msEndTime = max(msEndTime, msStartTime + pLap->GetTime()*1000);

      const vector<TimePoint2D>& lstPoints = pLap->GetPoints();
      float flRunningAverage[DATA_CHANNEL_COUNT];
      bool fUseRunningAverage[DATA_CHANNEL_COUNT] = {0};
      fUseRunningAverage[DATA_CHANNEL_X_ACCEL] = true;
      fUseRunningAverage[DATA_CHANNEL_Y_ACCEL] = true;
      fUseRunningAverage[DATA_CHANNEL_Z_ACCEL] = true;

      for(int msQuery = msStartTime; msQuery < msEndTime; msQuery += 100)
      {
        if(msQuery > msLastLine)
        {
          out<<ixLap<<",";

          TCHAR szTemp[100];
          _snwprintf(szTemp,NUMCHARS(szTemp),L"%6.3f",((float)msQuery/1000.0f)+flStartTime);
          out<<szTemp;

          TimePoint2D pt = ::GetPointAtTime(lstPoints,msQuery);
          _snwprintf(szTemp,NUMCHARS(szTemp),L"%4.6f",pt.flX);
          out<<","<<szTemp;
          _snwprintf(szTemp,NUMCHARS(szTemp),L"%4.6f",pt.flY);
          out<<","<<szTemp;

          for(map<DATA_CHANNEL,const IDataChannel*>::iterator i = begin(mapChannels); i != end(mapChannels); i++)
          {
            const IDataChannel* pDC = i->second;
            if(pDC)
            {
              float flValue = pDC->GetValue(msQuery);
              if(fUseRunningAverage[i->first])
              {
                flRunningAverage[i->first] = 0.7*flValue + 0.3*flRunningAverage[i->first];
              }
              _snwprintf(szTemp,NUMCHARS(szTemp),L"%5.2f",fUseRunningAverage[i->first] ? flRunningAverage[i->first] : flValue);
              out<<","<<szTemp;
            }
            else
            {
              out<<","; // if this lap didn't include the data channel, skip it
            }
          }
          out<<","<<endl;
          msLastLine = msQuery;
        }
      }
    }

    out.close();

    return S_OK;
  }
Beispiel #28
0
LRESULT CRaceSelectDlg::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch(uMsg)
  {
    case WM_INITDIALOG:
    {
      vector<wstring> lstCols;
      vector<int> lstWidths;
      lstCols.push_back(L"Date");
      lstCols.push_back(L"Race Name");
      lstCols.push_back(L"Laps");
      lstWidths.push_back(75);
      lstWidths.push_back(160);
      lstWidths.push_back(40);
      sfListBox.Init(GetDlgItem(hWnd,IDC_RACE),lstCols,lstWidths);

      // gotta set up the list
      vector<RACEDATA> lstRaces = m_pLapDB->GetRaces();
      
      for(int x = 0;x < lstRaces.size(); x++)
      {
        vector<wstring> lstCols;

        SYSTEMTIME stStart = SecondsSince1970ToSYSTEMTIME(lstRaces[x].unixtime);
        TCHAR szDate[100];
        _snwprintf(szDate,NUMCHARS(szDate),L"%d/%d/%4d",stStart.wMonth,stStart.wDay,stStart.wYear);
        lstCols.push_back(szDate);
              
        lstCols.push_back(lstRaces[x].strName.c_str());

        TCHAR szTemp[MAX_PATH];
        _snwprintf(szTemp, NUMCHARS(szTemp), L"%d",lstRaces[x].laps);
        lstCols.push_back(szTemp);

        sfListBox.AddStrings(lstCols,lstRaces[x].raceId);
      }

      break;
    }
    case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
        case IDOK:
        {
          set<LPARAM> set = sfListBox.GetSelectedItemsData();
          if(set.size() == 1)
          {
            m_pResults->iRaceId = *set.begin();
            m_pResults->fCancelled = false;
            EndDialog(hWnd,0);
          }
          else
          {
          }
          return TRUE;
        }
        case IDCANCEL:
          m_pResults->fCancelled = true;
          EndDialog(hWnd,0);
          return TRUE;
      }
      break;
    } // end WM_COMMAND
    case WM_CLOSE:
    {
      m_pResults->fCancelled = true;
      EndDialog(hWnd,0);
      break;
    }
  }
  return FALSE;
}
Beispiel #29
0
static int RecursiveDeleteDirectory(LPCTSTR pszPathIn, DWORD fdwFlags)
{
   BPRINT_BUFFER & bp = *g_pbpDiag;
   DeletePathData dpd;
   ZeroMemory(&dpd, sizeof(dpd));
   dpd.pbp = &g_bpErr;

   //this is for traversal testing...
   //dpd.fNoDelete = true;

   fdwFlags |= TDT_DIRLAST; // So we get directory callbacks after children have been deleted.

   // if the path isn't too long, convert to canonical form.  for long paths
   // they has better provide canonical form to begin with.
   //
   TCHAR szCanonPath[MAX_PATH+1];
   LPCTSTR pszPath = pszPathIn;
   if (lstrlen(pszPathIn) < MAX_PATH)
      {
      if (PathCanonicalize(szCanonPath, pszPathIn))
         pszPath = szCanonPath;      
      if (PathIsRelative(pszPath))
         return ERROR_INVALID_PARAMETER;
      }

   // the unicode versions of the windows file api's can handle very long
   // path names if they are canonical and if they are preceeded by \\?\.
   // if we are build unicode, take advantage of that capability.
   static const WCHAR szPre[]= L"\\\\?\\";
   WCHAR szFullPath[MAX_PATH + NUMCHARS(szPre)];
   WCHAR * pszFullPath = szFullPath;
   WCHAR * pszFilePart = NULL;

   lstrcpyW(szFullPath, szPre);
   MultiByteToWideChar(CP_ACP, 0, pszPath, -1, szFullPath + NUMCHARS(szPre)-1, MAX_PATH);
   /*
   UINT cchFullPath = GetFullPathNameW(pszPath, MAX_PATH, szFullPath + NUMCHARS(szPre)-1, &pszFilePart);
   if (cchFullPath >= NUMCHARS(szFullPath)-1)
      {
      pszFullPath = (TCHAR *)LocalAlloc(LPTR, (cchFullPath + NUMCHARS(szPre) + 2) * sizeof(WCHAR));
      if (pszFullPath)
         {
         lstrcpyW(pszFullPath, szPre);
         if (GetFullPathNameW(pszPath, cchFullPath+2, pszFullPath + NUMCHARS(szPre)-1, &pszFilePart) <= cchFullPath+2)
            pszPath = pszFullPath;
         }
      }
   else
      pszPath = szFullPath;
   */

   int err = 0;
   DWORD fdwFileAttributes = GetFileAttributesW(szFullPath);
   if (INVALID_FILE_ATTRIBUTES == fdwFileAttributes)
      {
      fdwFileAttributes = 0;
      err = GetLastError();
      ReportError(err, "Could not get attributes for ", pszPath);
      return err;
      }
   const bool fIsDir = (fdwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;

   if (fdwFlags & TDT_DIAGNOSTIC)
      bprintfl(bp, TEXT("Delete %s 0x%04X %s\\*"), fIsDir ? TEXT("Directory") : TEXT("File"), fdwFlags, pszPath);

   if (fIsDir)
      {
      err = TraverseDirectoryTreeW(szFullPath, L"*", fdwFlags, DeletePathCallback, &dpd, 0);
      if ( ! err || (fdwFlags & TDT_CONTINUE))
         {
         bprint_EndLine(bp);
         if ( ! dpd.fNoDelete && ! RemoveDirectoryW(szFullPath))
            {
            bprint_EndLine(bp);
            err = GetLastError();
            ReportError(err, "RemoveDirectory", pszPath);
            }
         }
      }
   else // initial path is a file, not a directory. 
      {
      if ( ! dpd.fNoDelete &&  ! DeleteFileW(szFullPath))
         {
         bprint_EndLine(bp);
         err = GetLastError();
         ReportError(err, "DeleteFile", pszPath);
         }
      }

   bprint_EndLine(bp);
   return err;
}
void CSQLiteLapDB::AddLap(const ILap* pLap, int _iRaceId)
{
  AutoLeaveCS _cs(&m_cs);
  CARNUMBERCOMBO sfCarNumber = pLap->GetCarNumbers();
  int iSaveRaceId = -1;
  if(mapCarNumberRaceIds.find(sfCarNumber) == mapCarNumberRaceIds.end())
  {
    // we've never seen this car number combo before.  Time for a new race.
    TCHAR szRaceName[200];
    if(sfCarNumber.IsOldVersion())
    {
      _snwprintf(szRaceName,NUMCHARS(szRaceName),L"Received from old wifilappers");
    }
    else
    {
      _snwprintf(szRaceName,NUMCHARS(szRaceName),L"Received laps (car %d) - (%d)", sfCarNumber.iCarNumber, sfCarNumber.iSecondaryCarNumber);
    }
    int iNewRaceId = -1;
    if(InitRaceSession(&iNewRaceId,szRaceName))
    {
      mapCarNumberRaceIds[sfCarNumber] = iNewRaceId;
      iSaveRaceId = iNewRaceId;
    }
    else
    {
      return;
    }
  }
  else
  {
    iSaveRaceId = mapCarNumberRaceIds[sfCarNumber];
  }

  m_setReceivingIds.insert(iSaveRaceId); // this race ID received a lap
  m_iLastRaceId = iSaveRaceId;

  m_sfDB.StartTransaction();

  bool fSuccess = true;
  CSfArtSQLiteQuery sfQuery(m_sfDB);
  if(sfQuery.Init(L"insert into laps (_id,laptime,unixtime,transmitted,raceid) values (?,?,?,?,?)"))
  {
    sfQuery.BindValue(pLap->GetLapId());
    sfQuery.BindValue(pLap->GetTime());
    sfQuery.BindValue(pLap->GetStartTime());
    sfQuery.BindValue(0);
    sfQuery.BindValue(iSaveRaceId);
    if(sfQuery.Next() || sfQuery.IsDone())
    {
      // inserted new data, hooray!

      vector<TimePoint2D> lstPoints = pLap->GetPoints();
      for(int x = 0;x < lstPoints.size(); x++)
      {
        const TimePoint2D& pt = lstPoints[x];
        sfQuery.DeInit();
        if(sfQuery.Init(L"insert into points (x,y,time,velocity,lapid) values (?,?,?,?,?)"))
        {
          sfQuery.BindValue(pt.flX);
          sfQuery.BindValue(pt.flY);
          sfQuery.BindValue(pt.iTime);
          sfQuery.BindValue(pt.flVelocity);
          sfQuery.BindValue(pLap->GetLapId());
          if(!sfQuery.Next() && !sfQuery.IsDone())
          {
            fSuccess = false;
            break;
          }
        }
      }
    }
    else
    {
      fSuccess = false;
    }
  }

  if(fSuccess)
  {
    mapLastRaceTimes[iSaveRaceId] = timeGetTime();
    m_pUI->NotifyChange(NOTIFY_NEWLAP,(LPARAM)this);
  }

  m_sfDB.StopTransaction();
}