view src/update.cpp @ 20:226774bf49fc

Small fix.
author pyon@macmini
date Mon, 08 Dec 2014 19:47:42 +0900
parents 1ba97995f642
children
line wrap: on
line source

// Filename   : update.cpp
// Last Change: 08-Dec-2014.

#include "update.h"

int CheckNewFiles( wxString shared )
{
    // index
    wxString cfile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
    wxFileName fn( cfile );
    wxDateTime ct = fn.GetModificationTime();

    wxString nfile = shared + wxFILE_SEP_PATH + wxT("ccn.db");
    fn.Assign( nfile );
    if ( !fn.IsFileReadable() ) {
        wxMessageBox( wxT("共有ファイルにアクセスできなかったので終了します。") );
        return 1;
    }
    wxDateTime nt = fn.GetModificationTime();

    if ( nt - ct > wxTimeSpan::Week() ) {
        wxMessageDialog md( NULL, wxT("インデックスが古くなっています.\n新しいインデックスを取得しますか?"), wxT("Information"), wxYES_NO|wxOK_DEFAULT );
        if ( md.ShowModal() == wxID_YES ) {
            GetFile( cfile, nfile );
        }
    }
    else {
        if ( ct - nt > wxTimeSpan::Day() )
            PutFile( nfile, cfile );
    }

    // hhs
    cfile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db");
    fn.Assign( cfile );
    ct = fn.GetModificationTime();

    nfile = shared + wxFILE_SEP_PATH + wxT("hhs.db");
    fn.Assign( nfile );
    nt = fn.GetModificationTime();

    if ( nt - ct > wxTimeSpan::Week() ) {
        wxMessageDialog md( NULL, wxT("被保険者情報の最新版があります.\n被保険者情報を取得しますか?"), wxT("Information"), wxYES_NO|wxOK_DEFAULT );
        if ( md.ShowModal() == wxID_YES ) {
            GetFile( cfile, nfile );
        }
    }
    else {
        if ( ct - nt > wxTimeSpan::Day() )
            PutFile( nfile, cfile );
    }

    return 0;
}

void GetFile( wxString target, wxString newfile )
{
    wxCopyFile( newfile, target, true );
    wxMessageBox( wxT("アップデート完了.") );
}

void PutFile( wxString newfile, wxString target )
{
    wxCopyFile( target, newfile, true );
}