fixed a bug with creating databases

This commit is contained in:
Philipp Crocoll 2013-07-15 20:42:16 +02:00
parent 72ab132979
commit ed7a85dde7

View File

@ -54,14 +54,15 @@ namespace keepass2android
public override void Run () public override void Run ()
{ {
if (! _dontSave) { if (!_dontSave)
{
try try
{ {
StatusLogger.UpdateMessage(UiStringKey.saving_database); StatusLogger.UpdateMessage(UiStringKey.saving_database);
IOConnectionInfo ioc = _app.GetDb().Ioc; IOConnectionInfo ioc = _app.GetDb().Ioc;
IFileStorage fileStorage = _app.GetFileStorage(ioc); IFileStorage fileStorage = _app.GetFileStorage(ioc);
if ((!_app.GetBooleanPreference(PreferenceKey.CheckForFileChangesOnSave)) if ((!_app.GetBooleanPreference(PreferenceKey.CheckForFileChangesOnSave))
|| (_app.GetDb().KpDatabase.HashOfFileOnDisk == null)) //first time saving || (_app.GetDb().KpDatabase.HashOfFileOnDisk == null)) //first time saving
{ {
@ -70,42 +71,42 @@ namespace keepass2android
return; return;
} }
if (fileStorage.CheckForFileChangeFast(ioc, _app.GetDb().LastFileVersion) //first try to use the fast change detection if (fileStorage.CheckForFileChangeFast(ioc, _app.GetDb().LastFileVersion) //first try to use the fast change detection
|| (FileHashChanged(ioc, _app.GetDb().KpDatabase.HashOfFileOnDisk))) //if that fails, hash the file and compare: || (FileHashChanged(ioc, _app.GetDb().KpDatabase.HashOfFileOnDisk))) //if that fails, hash the file and compare:
{ {
//ask user... //ask user...
_app.AskYesNoCancel(UiStringKey.TitleSyncQuestion, UiStringKey.MessageSyncQuestion, _app.AskYesNoCancel(UiStringKey.TitleSyncQuestion, UiStringKey.MessageSyncQuestion,
//yes = sync //yes = sync
(sender, args) => (sender, args) =>
{ {
Action runHandler = () => Action runHandler = () =>
{ {
//note: when synced, the file might be downloaded once again from the server. Caching the data //note: when synced, the file might be downloaded once again from the server. Caching the data
//in the hashing function would solve this but increases complexity. I currently assume the files are //in the hashing function would solve this but increases complexity. I currently assume the files are
//small. //small.
MergeIn(fileStorage, ioc); MergeIn(fileStorage, ioc);
PerformSaveWithoutCheck(fileStorage, ioc); PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true); Finish(true);
}; };
RunInWorkerThread(runHandler); RunInWorkerThread(runHandler);
}, },
//no = overwrite //no = overwrite
(sender, args) => (sender, args) =>
{ {
RunInWorkerThread( () => RunInWorkerThread(() =>
{ {
PerformSaveWithoutCheck(fileStorage, ioc); PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true); Finish(true);
}); });
}, },
//cancel //cancel
(sender, args) => (sender, args) =>
{ {
RunInWorkerThread(() => Finish(false)); RunInWorkerThread(() => Finish(false));
}, },
_ctx _ctx
); );
} }
@ -114,8 +115,10 @@ namespace keepass2android
PerformSaveWithoutCheck(fileStorage, ioc); PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true); Finish(true);
} }
} catch (Exception e) { }
catch (Exception e)
{
/* TODO KPDesktop: /* TODO KPDesktop:
* catch(Exception exSave) * catch(Exception exSave)
{ {
@ -123,12 +126,15 @@ namespace keepass2android
bSuccess = false; bSuccess = false;
} }
*/ */
Kp2aLog.Log("Error while saving: "+e.ToString()); Kp2aLog.Log("Error while saving: " + e.ToString());
Finish (false, e.Message); Finish(false, e.Message);
return; return;
} }
}
else
{
Finish(true);
} }
} }