Пример #1
0
int PhdApp::OnExit(void)
{
    assert(pMount == NULL);
    assert(pSecondaryMount == NULL);
    assert(pCamera == NULL);

    PhdController::OnAppExit();

    Debug.RemoveOldFiles();
    GuideLog.RemoveOldFiles();

    delete pConfig;
    pConfig = NULL;

    delete m_instanceChecker; // OnExit() won't be called if we return false
    m_instanceChecker = 0;

    return wxApp::OnExit();
}
Пример #2
0
bool PhdApp::OnInit()
{
    if (!wxApp::OnInit())
    {
        return false;
    }

    m_instanceChecker = new wxSingleInstanceChecker(wxString::Format("%s.%ld", GetAppName(), m_instanceNumber));
    if (m_instanceChecker->IsAnotherRunning())
    {
        wxLogError(wxString::Format(_("PHD2 instance %ld is already running. Use the "
            "-i INSTANCE_NUM command-line option to start a different instance."), m_instanceNumber));
        delete m_instanceChecker; // OnExit() won't be called if we return false
        m_instanceChecker = 0;
        return false;
    }

#ifndef DEBUG
    #if (wxMAJOR_VERSION > 2 || wxMINOR_VERSION > 8)
    wxDisableAsserts();
    #endif
#endif

    SetVendorName(_T("StarkLabs"));
    // use SetAppName() to ensure the local data directory is found even if the name of the executable is changed
#ifdef __APPLE__
    SetAppName(_T("PHD2"));
#else
    SetAppName(_T("phd2"));
#endif
    pConfig = new PhdConfig(_T("PHDGuidingV2"), m_instanceNumber);

    Debug.Init("debug", true);

    Debug.AddLine(wxString::Format("PHD2 version %s begins execution with:", FULLVER));
    Debug.AddLine(wxString::Format("   %s", wxVERSION_STRING));
    float dummy;
    Debug.AddLine(wxString::Format("   cfitsio %.2lf", ffvers(&dummy)));
#if defined(CV_VERSION)
    Debug.AddLine(wxString::Format("   opencv %s", CV_VERSION));
#endif

#if defined(__WINDOWS__)
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    Debug.AddLine("CoInitializeEx returns %x", hr);
#endif

    DisableOSXAppNap();

    if (m_resetConfig)
    {
        pConfig->DeleteAll();
    }

    wxString ldir = wxStandardPaths::Get().GetResourcesDir() + PATHSEPSTR "locale";
    if (!wxDirExists(ldir))
    {
        // for development environments
        ldir = _T("locale");
    }
    bool ex = wxDirExists(ldir);
    Debug.AddLine(wxString::Format("Using Locale Dir %s exists=%d", ldir, ex));
    wxLocale::AddCatalogLookupPathPrefix(ldir);
    m_localeDir = ldir;

    m_locale.Init(pConfig->Global.GetInt("/wxLanguage", wxLANGUAGE_DEFAULT));
    if (!m_locale.AddCatalog(PHD_MESSAGES_CATALOG))
    {
        Debug.AddLine("locale.AddCatalog failed");
    }
    wxSetlocale(LC_NUMERIC, "C");

    Debug.RemoveOldFiles();
    GuideLog.RemoveOldFiles();

    pConfig->InitializeProfile();

    PhdController::OnAppInit();

    wxImage::AddHandler(new wxJPEGHandler);
    wxImage::AddHandler(new wxPNGHandler);

    pFrame = new MyFrame(m_instanceNumber, &m_locale);

    pFrame->Show(true);

    if (pConfig->IsNewInstance() || (pConfig->NumProfiles() == 1 && pFrame->pGearDialog->IsEmptyProfile()))
    {
        pFrame->pGearDialog->ShowProfileWizard();               // First-light version of profile wizard
    }

    return true;
}