Esempio n. 1
0
//Read account file and store information into bank's accounts vector
void Bank::readAccounts() {
	ifstream account_file("accounts_input.txt");
	if (!account_file) {
		cout << "accounts_input.txt not found." << endl;
	}
	while (!account_file.eof()) {
		account_file >> pAccounts;
	}
}
Esempio n. 2
0
/***********************************************************************************
 **
 **
 ** MailRecovery::CheckAndFixAccountSpecificDBs
 ***********************************************************************************/
OP_STATUS MailRecovery::CheckAndFixAccountSpecificDBs()
{
    OpString account_filename;
    RETURN_IF_ERROR(MailFiles::GetAccountsINIFilename(account_filename));

    OpFile file;
    RETURN_IF_ERROR(file.Construct(account_filename.CStr()));
    PrefsFile account_file(PREFS_INI);
    RETURN_IF_LEAVE(account_file.ConstructL());
    RETURN_IF_LEAVE(account_file.SetFileL(&file));

    RETURN_IF_LEAVE(account_file.LoadAllL());

    int accounts_version;

    RETURN_IF_ERROR(PrefsUtils::ReadPrefsInt(&account_file, "Accounts", "Version", CURRENT_M2_ACCOUNT_VERSION, accounts_version));

    OpStringC8 log_heading("Account version issue");

    if (accounts_version > CURRENT_M2_ACCOUNT_VERSION)
    {
        OpStatus::Ignore(DesktopFileLogger::Log(m_recovery_log,log_heading,"Can't recover newer files than currently supported, you need to upgrade"));
        return OpStatus::ERR_OUT_OF_RANGE; // refuse to recover
    }

    if (accounts_version < CURRENT_M2_ACCOUNT_VERSION)
    {
        OpStatus::Ignore(DesktopFileLogger::Log(m_recovery_log,log_heading,"Can't recover old files, you need to let m2 upgrade your files first"));
        return OpStatus::ERR_OUT_OF_RANGE; // refuse to recover
    }

    // Read sections, each section is an account, except the first one
    OpString_list section_list;
    RETURN_IF_LEAVE(account_file.ReadAllSectionsL(section_list));

    // in the first section read the version number, if m2 needs an upgrade then we can't do a recovery yet ( but on next startup )
    for (unsigned long i = 1; i < section_list.Count(); i++)
    {
        OpString8 account_str, protocol;
        RETURN_IF_ERROR(account_str.Set(section_list.Item(i).CStr()));
        RETURN_IF_ERROR(PrefsUtils::ReadPrefsString(&account_file, account_str, "Incoming Protocol", protocol));

        int account_number;
        if (sscanf(account_str.CStr(), "Account%d", &account_number) == 1)
        {
            AccountTypes::AccountType type = Account::GetProtocolFromName(protocol);
            switch (type)
            {
            case AccountTypes::POP:
            {
                if (OpStatus::IsError(CheckAndFixPOPDatabase(account_number)))
                {
                    // implement error handling
                }
                break;
            }
            case AccountTypes::IMAP:
            {
                if (OpStatus::IsError(CheckAndFixIMAPDatabase(account_number)))
                {
                    // implement error handling
                }
                break;
            }
            case AccountTypes::RSS:
            {
                if (OpStatus::IsError(CheckAndFixFeedDatabases()))
                {
                    // implement error handling
                }
                break;
            }
            default:
                break;
            }
        }
    }
    return OpStatus::OK;
}