Example #1
0
// This removes the csync File database if the sync folder definition is removed
// permanentely. This is needed to provide a clean startup again in case another
// local folder is synced to the same ownCloud.
// See http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-788
void Folder::wipe()
{
    QString stateDbFile = path()+QLatin1String(".csync_journal.db");

    QFile file(stateDbFile);
    if( file.exists() ) {
        if( !file.remove()) {
            qDebug() << "WRN: Failed to remove existing csync StateDB " << stateDbFile;
        } else {
            qDebug() << "wipe: Removed csync StateDB " << stateDbFile;
        }
    } else {
        qDebug() << "WRN: statedb is empty, can not remove.";
    }
    // Check if the tmp database file also exists
    QString ctmpName = path() + QLatin1String(".csync_journal.db.ctmp");
    QFile ctmpFile( ctmpName );
    if( ctmpFile.exists() ) {
        ctmpFile.remove();
    }
}
bool ClassGenerateDialog::GenerateClass(Table* pTab, const wxString& path)
{
    wxString hFileName = wxT("");
    wxString cFileName = wxT("");

    wxArrayString arrFileNames = wxStringTokenize( m_mapTemplateFiles[ m_choiceTemplates->GetStringSelection() ],
                                 wxT(";"),
                                 wxTOKEN_RET_EMPTY );

    if (pTab->IsView()) {
        hFileName = arrFileNames[2];
        cFileName = arrFileNames[3];

    } else {
        hFileName = arrFileNames[0];
        cFileName = arrFileNames[1];
    }

    wxTextFile htmpFile(m_mgr->GetInstallDirectory() + wxT("/templates/databaselayer/") + hFileName);
    wxTextFile ctmpFile(m_mgr->GetInstallDirectory() + wxT("/templates/databaselayer/") + cFileName);

    if (!htmpFile.Open() || !ctmpFile.Open()) return false;

    classTableName = pTab->GetName();
    classItemName = m_txPrefix->GetValue() + pTab->GetName() + m_txPostfix->GetValue();
    classItemDef = wxT("__") + classItemName.Upper() + wxT("_H__");
    classColName = m_txPrefix->GetValue() + pTab->GetName() + wxT("Collection")+ m_txPostfix->GetValue();
    classUtilName = m_txPrefix->GetValue() + pTab->GetName() + wxT("Utils")+ m_txPostfix->GetValue();

    wxString hFile;
    wxFileName fnHeaderFileName(path + wxT("/") + classItemName + wxT(".h"));
    
    wxString cFile;
    wxFileName fnCppFileName(path + wxT("/") + classItemName + wxT(".cpp"));
    
    bool suc = GenerateFile(pTab,htmpFile, hFile, classItemName, classItemDef,classColName,classTableName, classUtilName);
    suc &= GenerateFile(pTab, ctmpFile, cFile, classItemName, classItemDef,classColName,classTableName, classUtilName);

    htmpFile.Close();
    ctmpFile.Close();

    // format output files
    FormatFile( hFile );
    FormatFile( cFile );

    ::WriteFileWithBackup(fnCppFileName.GetFullPath(), cFile, false);
    ::WriteFileWithBackup(fnHeaderFileName.GetFullPath(), hFile, false);

    // add files to the workspace
    wxArrayString arrString;
    arrString.Add( path + wxT("/") + classItemName + wxT(".h"));
    arrString.Add( path + wxT("/") + classItemName + wxT(".cpp"));

    m_mgr->AddFilesToVirtualFolder( m_txVirtualDir->GetValue(), arrString );

    // retag workspace
    wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, XRCID("retag_workspace") );
    EventNotifier::Get()->TopFrame()->GetEventHandler()->AddPendingEvent( evt );

    return suc;
}