bool NMEALogger::Start() { if (writer != nullptr) return true; BrokenDateTime dt = BrokenDateTime::NowUTC(); assert(dt.IsPlausible()); StaticString<64> name; name.Format(_T("%04u-%02u-%02u_%02u-%02u.nmea"), dt.year, dt.month, dt.day, dt.hour, dt.minute); const auto logs_path = MakeLocalPath(_T("logs")); const auto path = AllocatedPath::Build(logs_path, name); writer = new TextWriter(path, false); if (writer == nullptr) return false; if (!writer->IsOpen()) { delete writer; writer = nullptr; return false; } return true; }
void TaskListPanel::RenameTask() { const unsigned cursor_index = GetList().GetCursorIndex(); if (cursor_index >= task_store->Size()) return; const TCHAR *oldname = task_store->GetName(cursor_index); StaticString<40> newname(oldname); if (ClearSuffix(newname.buffer(), _T(".cup"))) { ShowMessageBox(_("Can't rename .CUP files"), _("Rename Error"), MB_ICONEXCLAMATION); return; } ClearSuffix(newname.buffer(), _T(".tsk")); if (!TextEntryDialog(newname)) return; newname.append(_T(".tsk")); const auto tasks_path = MakeLocalPath(_T("tasks")); File::Rename(task_store->GetPath(cursor_index), AllocatedPath::Build(tasks_path, newname)); task_store->Scan(more); RefreshView(); }
bool OrderedTaskSave(OrderedTask &task) { TCHAR fname[69] = _T(""); if (!TextEntryDialog(fname, 64, _("Enter a task name"))) return false; const auto tasks_path = MakeLocalPath(_T("tasks")); _tcscat(fname, _T(".tsk")); task.SetName(StaticString<64>(fname)); SaveTask(AllocatedPath::Build(tasks_path, fname), task); return true; }
void Image::MakeProxy( double scale ) // from full adib, make scaled version and save to file { ADib *proxy; char suffix[MAX_PATH], dir[MAX_PATH], file[MAX_PATH]; if ( LoadAdib( false, 0.0 ) ) // pixel_size is irrelevant becuz no proxy read allowed { proxy = new ADib( *adib, scale ); // create scaled replica proxy->ConvertUpTo24bit(); // JPEG saves only in 24-bit color proxyScale = scale; MakeLocalPath(ImagesPath,src,proxySrc); // get path relative to ImagesPath strcat( proxySrc, "_proxy.jpg" ); // tack on proxy suffix to make unique name proxy->SaveADibAsJPEG( proxySrc, 70 ); // save with moderate compression delete proxy; } }
bool LoggerImpl::StartLogger(const NMEAInfo &gps_info, const LoggerSettings &settings, const char *logger_id) { assert(logger_id != nullptr); assert(strlen(logger_id) == 3); /* finish the previous IGC file */ StopLogger(gps_info); assert(writer == nullptr); const auto logs_path = MakeLocalPath(_T("logs")); const BrokenDate today = gps_info.date_time_utc.IsDatePlausible() ? (const BrokenDate &)gps_info.date_time_utc : BrokenDate::TodayUTC(); StaticString<64> name; for (int i = 1; i < 99; i++) { FormatIGCFilenameLong(name.buffer(), today, "XCS", logger_id, i); filename = AllocatedPath::Build(logs_path, name); if (!File::Exists(filename)) break; // file not exist, we'll use this name } frecord.Reset(); try { writer = new IGCWriter(filename); } catch (...) { LogError(std::current_exception()); return false; } LogFormat(_T("Logger Started: %s"), filename.c_str()); return true; }
bool Image::LoadAdib( bool useProxy, double pixel_size ) // load Adib from file { // base proxy load on flag and pixel_size int id; UINT lastErrorMode; double psize; char basename[MAX_BASE], suffix[MAX_PATH], dir[MAX_PATH], filename[MAX_PATH]; // begin debug logging... DWORD byteswritten; char debugline[MAX_PATH]; if ( debugLogFile != INVALID_HANDLE_VALUE ) { sprintf(debugline,"Entered Image::LoadAdib\r\n"); WriteFile(debugLogFile, debugline, strlen(debugline), &byteswritten, NULL); } // ...end debug logging lastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); // turn off Windows error dialogs switch ( loaded ) // determine if adib already loaded correctly { case SOURCE: if ( adib == NULL ) loaded = NONE; // need to do full source load break; case SKIPPED: // user has already said to skip loading break; case PROXY: // is proxy appropriate at this resolution? psize = mag/proxyScale; // compute (bigger) pixel_size of proxy if ( useProxy && (strlen(proxySrc)>0) && (proxyScale<1.0) && ( psize < (pixel_size - mag) ) ) // if less than one full pixel difference if ( adib ) break; // then OK to use it the loaded proxy image // else fall through to retry proxy load in case (adib==NULL) default: loaded = NONE; // reset to NONE here, may need full src load SetCurrentDirectory(ImagesPath); // source path may be relative to images folder! psize = mag/proxyScale; // compute (bigger) pixel_size of proxy if ( useProxy && (strlen(proxySrc)>0) && (proxyScale<1.0) && ( psize < (pixel_size - mag) ) ) // if less than one full pixel difference { if ( adib ) delete adib; // attempt proxy load adib = new ADib( proxySrc ); if ( adib->bits ) loaded = PROXY; // successful proxy loaded } // if reach this point, will need to try full src load... } while ( loaded == NONE ) // keep trying until found or skipped { if ( adib ) delete adib; // throw out existing proxy adib adib = new ADib( src ); // try to load full sized image if ( adib->bits ) loaded = SOURCE; else // else failed, show missing file dialog { if ( adib ) delete adib; // throw out existing adib from above failed attempt adib = NULL; // set to NULL so will correctly fail in ADib if ( SkipAllMissing ) loaded = SKIPPED; // if user never wants to find it, then done else { // ask user to find file strcpy( InputDlgString, src ); id = DialogBox( appInstance, "MissingDlg", appWnd, (DLGPROC)MissingDlgProc ); if ( id == ID_SKIPALL ) SkipAllMissing = true; if ( (id == ID_SKIPALL) || (id == ID_SKIPFILE) ) loaded = SKIPPED; } if ( loaded != SKIPPED ) // if user chooses skip, then return w/o loading { SplitPath(InputDlgString,dir,filename,suffix);// user found a new filepath! parse it if ( SetCurrentDirectory(dir) ) { // try new path as default images path strcpy(ImagesPath,dir); MakeLocalPath(ImagesPath,InputDlgString,src); } else strcpy(src,InputDlgString); // otherwise, just use user's filepath } } } SetErrorMode( lastErrorMode ); // restore Windows error dialogs if ( (loaded == SOURCE) || (loaded == PROXY) ) return true; else return false; // failure if no image is available }
void ExternalLogger::DownloadFlightFrom(DeviceDescriptor &device) { MessageOperationEnvironment env; // Download the list of flights that the logger contains RecordedFlightList flight_list; switch (DoReadFlightList(device, flight_list)) { case TriStateJobResult::SUCCESS: break; case TriStateJobResult::ERROR: device.EnableNMEA(env); ShowMessageBox(_("Failed to download flight list."), _("Download flight"), MB_OK | MB_ICONERROR); return; case TriStateJobResult::CANCELLED: return; } // The logger seems to be empty -> cancel if (flight_list.empty()) { device.EnableNMEA(env); ShowMessageBox(_("Logger is empty."), _("Download flight"), MB_OK | MB_ICONINFORMATION); return; } const auto logs_path = MakeLocalPath(_T("logs")); while (true) { // Show list of the flights const RecordedFlightInfo *flight = ShowFlightList(flight_list); if (!flight) break; // Download chosen IGC file into temporary file FileTransaction transaction(AllocatedPath::Build(logs_path, _T("temp.igc"))); switch (DoDownloadFlight(device, *flight, transaction.GetTemporaryPath())) { case TriStateJobResult::SUCCESS: break; case TriStateJobResult::ERROR: ShowMessageBox(_("Failed to download flight."), _("Download flight"), MB_OK | MB_ICONERROR); continue; case TriStateJobResult::CANCELLED: continue; } /* read the IGC header and build the final IGC file name with it */ IGCHeader header; BrokenDate date; ReadIGCMetaData(transaction.GetTemporaryPath(), header, date); if (header.flight == 0) header.flight = GetFlightNumber(flight_list, *flight); TCHAR name[64]; FormatIGCFilenameLong(name, date, header.manufacturer, header.id, header.flight); transaction.SetPath(AllocatedPath::Build(logs_path, name)); transaction.Commit(); if (ShowMessageBox(_("Do you want to download another flight?"), _("Download flight"), MB_YESNO | MB_ICONQUESTION) != IDYES) break; } device.EnableNMEA(env); }