23 #if( FMI_SUPPORT_A622 ) 36 ON_BN_CLICKED( IDOK, OnBnClickedOk )
54 {
CONV_PSR_TO_CSV, _T(
"PSR to CSV" ), NULL, _T(
".csv"), _T(
"PSR Files (*.*)|*.*|" ) },
55 {
CONV_CSV_TO_PSR, _T(
"CSV to PSR" ), NULL, _T(
".psr"), _T(
"CSV Files (*.csv)|*.csv|" ) },
56 {
CONV_GPX_TO_PSR, _T(
"GPX to PSR" ), NULL, _T(
".psr"), _T(
"GPX Files (*.gpx)|*.gpx|" ) }
71 , mConversionType( 0 )
72 , mSrcFilePath( _T(
"") )
73 , mDstFileName( _T(
"") )
74 , mDstFolder( _T(
"") )
75 , mConversionIndex( 0 )
77 , mRouteName( _T(
"") )
96 CDataExchange * aDataExchange
99 CDialog::DoDataExchange( aDataExchange );
125 CDialog::OnInitDialog();
130 for(
int i = 0; i <
cnt_of_array( conversion_types ); i++ )
132 cbo->AddString( conversion_types[i].text );
135 mConversionType = conversion_types[0].
index;
162 dstFilePath = mDstFolder;
163 if( !( dstFilePath.Right( 1 ) == _T(
"\\") ) )
165 dstFilePath.Append( _T(
"\\") );
167 dstFilePath.Append( mDstFileName );
172 if( CFile::GetStatus( dstFilePath, status ) != 0 )
174 if( MessageBox( _T(
"Destination File already exists. Overwrite File?"), _T(
"Caution"), MB_YESNO ) == IDNO )
197 SECURITY_ATTRIBUTES saAttr;
198 saAttr.nLength =
sizeof( SECURITY_ATTRIBUTES );
199 saAttr.bInheritHandle =
TRUE;
200 saAttr.lpSecurityDescriptor = NULL;
203 if ( ! CreatePipe( &hChildStd_OUT_Rd, &hChildStd_OUT_Wr, &saAttr, 0 ) )
return;
206 if ( ! SetHandleInformation( hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0 ) )
return;
208 result = CreateChildProcess( dstFilePath );
213 output.Format( _T(
"Successfully Converted the File.\n\nFile sent to:\n%s"),
214 (LPCTSTR)dstFilePath );
215 MessageBox( output, _T(
"Conversion Complete") );
229 mSrcFilePath.Insert( 0,
'\"' );
230 mSrcFilePath.AppendChar(
'\"' );
231 dstFilePath.Insert( 0,
'\"' );
232 dstFilePath.AppendChar(
'\"' );
233 mRouteName.Insert( 0,
'\"' );
234 mRouteName.AppendChar(
'\"' );
237 switch( mConversionType )
241 arguments.Append( mSrcFilePath );
242 arguments.Append( _T(
" "));
243 arguments.Append( dstFilePath );
244 arguments.Append( _T(
" -D ") );
245 arguments.AppendFormat( _T(
"%i"), mDstCoords );
249 arguments.Append( mSrcFilePath );
250 arguments.Append( _T(
" "));
251 arguments.Append( dstFilePath );
252 arguments.Append( _T(
" -R ") );
253 arguments.Append( mRouteName );
254 arguments.Append( _T(
" -I ") );
255 arguments.Append( mStopId );
256 arguments.Append( _T(
" -S ") );
257 arguments.AppendFormat( _T(
"%i"), mSrcCoords );
261 arguments.Append( mSrcFilePath );
262 arguments.Append( _T(
" "));
263 arguments.Append( dstFilePath );
264 arguments.Append( _T(
" -I ") );
265 arguments.Append( mStopId );
268 arguments.Append( _T(
"-H") );
283 TCHAR workingDirectory[200];
289 DWORD result = GetCurrentDirectory( 200, workingDirectory );
290 if( result == 0 || result > 200 )
292 MessageBox( _T(
"Unable to get current directory"), _T(
"Severe Error") );
299 conversion_types[ mConversionIndex ].extension,
301 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
302 conversion_types[ mConversionIndex ].filter
304 if( dlg.DoModal() == IDOK )
306 mSrcFilePath = dlg.GetPathName();
307 mDstFileName = dlg.GetFileTitle();
308 mDstFileName.Append( conversion_types[ mConversionIndex ].newExtension );
309 mDstFolder = dlg.GetFolderPath();
313 if( !SetCurrentDirectory( workingDirectory ) )
315 MessageBox( _T(
"Unable to set current directory"), _T(
"Severe Error") );
334 ZeroMemory( &bi,
sizeof( bi ) );
335 TCHAR szDisplayName[MAX_PATH];
336 szDisplayName[0] = NULL;
339 bi.hwndOwner = ::GetDesktopWindow();
341 bi.pszDisplayName = szDisplayName;
342 bi.lpszTitle = _T(
"Please select a folder:" );
343 bi.ulFlags = BIF_USENEWUI|BIF_RETURNONLYFSDIRS;
348 if ( ::SHGetMalloc( &pMalloc ) == NOERROR )
350 if( NULL != ( pidl = SHBrowseForFolder( &bi ) ) )
352 TCHAR szPathName[MAX_PATH];
353 if( SHGetPathFromIDList( pidl, szPathName ) )
355 mDstFolder = szPathName;
374 mConversionIndex = cbo->GetCurSel();
375 mConversionType = conversion_types[mConversionIndex].
index;
414 ced->SetWindowTextW( _T(
"") );
416 ced->SetWindowTextW( _T(
"") );
418 ced->SetWindowTextW( _T(
"") );
420 ced->SetWindowTextW( _T(
"") );
422 ced->SetWindowTextW( _T(
"") );
438 if( mSrcFilePath ==
"" || mDstFileName ==
"" || mDstFolder ==
"" )
442 if( mConversionType ==
CONV_CSV_TO_PSR && ( mStopId ==
"" || mRouteName ==
"" ) )
453 GetDlgItem( IDOK )->EnableWindow(
TRUE );
457 GetDlgItem( IDOK )->EnableWindow(
FALSE );
469 PROCESS_INFORMATION piProcInfo;
470 STARTUPINFO siStartInfo;
471 BOOL bSuccess =
FALSE;
474 ZeroMemory( &piProcInfo,
sizeof(PROCESS_INFORMATION) );
478 ZeroMemory( &siStartInfo,
sizeof(STARTUPINFO) );
479 siStartInfo.cb =
sizeof(STARTUPINFO);
480 siStartInfo.hStdError = hChildStd_OUT_Wr;
482 siStartInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
483 siStartInfo.wShowWindow = SW_HIDE;
486 const int MAX_CMDLINE = 1000;
487 WCHAR modulePath[MAX_PATH];
488 ZeroMemory( &modulePath, MAX_PATH );
489 WCHAR fullPathBuffer[MAX_CMDLINE];
490 WCHAR exe[] = _T(
"\\FleetFileUtility.exe");
491 GetModuleFileName( NULL, modulePath, MAX_PATH );
492 PathRemoveFileSpec( modulePath );
493 wcscat_s( modulePath, exe );
494 wstring actualPath( modulePath );
495 actualPath.insert(0, L
"\"");
496 actualPath.append(L
"\" ");
497 CString parameters = FormatArguments( dstFilePath );
498 actualPath.append( (wstring)parameters );
499 wcscpy_s( fullPathBuffer, actualPath.size()+1, actualPath.c_str() );
502 bSuccess = CreateProcess
517 GetDlgItem( IDOK )->EnableWindow(
FALSE );
518 GetDlgItem( IDCANCEL )->EnableWindow(
FALSE );
520 WaitForSingleObject( piProcInfo.hProcess, INFINITE );
521 GetDlgItem( IDOK )->EnableWindow(
TRUE );
522 GetDlgItem( IDCANCEL )->EnableWindow(
TRUE );
526 GetExitCodeProcess( piProcInfo.hProcess, &prcRes );
527 bSuccess = (BOOL)prcRes;
531 MessageBox( _T(
"Unable to locate the Fleet File Utility. Make sure the")
532 _T(
" FleetFileUtility.exe is in the same location as the Fleet")
533 _T(
"ManagementController.exe and try again.")
534 , _T(
"Severe Error") );
537 CloseHandle( piProcInfo.hProcess );
538 CloseHandle( piProcInfo.hThread );
549 const int BUFSIZE = 4096;
552 ZeroMemory( chBuf, BUFSIZE );
553 BOOL bSuccess =
FALSE;
555 CloseHandle( hChildStd_OUT_Wr );
558 bSuccess = ReadFile( hChildStd_OUT_Rd, chBuf, BUFSIZE, &dwRead, NULL );
561 CString output( chBuf );
562 MessageBox( output, _T(
"Fleet File Utility" ) );
#define IDC_FILE_CONVERT_EDIT_DST_FILENAME
#define IDC_FILE_CONVERT_RADB_2
#define IDC_FILE_CONVERT_RADB_1
BOOL CreateChildProcess(CString dstFilePath)
Create a child process to execute the file conversion.
#define IDC_FILE_CONVERT_EDIT_DST_FOLDER
#define IDC_FILE_CONVERT_BTN_CHOOSE
#define IDC_FILE_CONVERT_EDIT_SRC_FILENAME
static CFileConverterDlg::conversion_type conversion_types[]
Conversion types that the client accepts.
#define cnt_of_array(_a)
The number of elements in _a.
virtual ~CFileConverterDlg()
Destructor.
BOOL OnInitDialog()
Initialize the dialog.
#define IDC_FILE_CONVERT_CBO_TYPE
afx_msg void OnBnClickedOk()
Click handler for OK button.
#define IDC_FILE_CONVERT_BTN_FIND
#define IDC_FILE_CONVERT_RADB_3
Serial communication controller for Garmin and FMI packets.
afx_msg void OnBnClickedFind()
Click handler for Find (file to convert) button.
afx_msg void OnBnClickedChoose()
Click handler for Choose (destination folder) button.
afx_msg void OnEnChangeFile()
Edit Change handler for all text boxes.
File conversion tool to support various GPS file formats.
CFileConverterDlg(CWnd *aParent, FmiApplicationLayer &aCom)
Constructor.
conversion_type_type
Valid values for file conversion types.
#define IDC_FILE_CONVERT_EDIT_STOPID
afx_msg void OnComboChanged()
Change Handler for the combo box.
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
CString FormatArguments(CString dstFilePath)
Helper function to format the command line arguments.
#define IDC_FILE_CONVERT_RADB_4
#define IDC_FILE_CONVERT_EDIT_ROUTE_NAME
void ReadFromPipe(void)
Read output from the child process's pipe for STDOUT.