This commit is contained in:
AlexVallat
2013-07-24 08:12:45 +01:00
60 changed files with 865 additions and 213 deletions

View File

@@ -50,6 +50,16 @@ namespace keepass2android
EventHandler<DialogClickEventArgs> yesHandler,
EventHandler<DialogClickEventArgs> noHandler,
EventHandler<DialogClickEventArgs> cancelHandler,
Context ctx);
/// <summary>
/// Asks the user the question "messageKey" with the options Yes/No/Cancel, but the yes/no strings can be selected freely, calls the handler corresponding to the answer.
/// </summary>
void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey,
UiStringKey yesString, UiStringKey noString,
EventHandler<DialogClickEventArgs> yesHandler,
EventHandler<DialogClickEventArgs> noHandler,
EventHandler<DialogClickEventArgs> cancelHandler,
Context ctx);
/// <summary>

View File

@@ -32,6 +32,16 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseNoNet|AnyCPU'">
<OutputPath>bin\ReleaseNoNet\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />

View File

@@ -30,5 +30,4 @@ using Android.App;
[assembly: AssemblyFileVersion("1.0.0.0")]
// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]

View File

@@ -30,6 +30,10 @@ namespace keepass2android
CheckingTargetFileForChanges,
TitleSyncQuestion,
MessageSyncQuestion,
SynchronizingDatabase
SynchronizingDatabase,
yes,
no,
YesSynchronize,
NoOverwrite
}
}

View File

@@ -15,14 +15,16 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using Android.Content;
using Java.Lang;
using KeePassLib;
using KeePassLib.Keys;
using KeePassLib.Serialization;
using keepass2android.Io;
using Exception = System.Exception;
using String = System.String;
namespace keepass2android
{
@@ -35,7 +37,13 @@ namespace keepass2android
public HashSet<PwGroup> Dirty = new HashSet<PwGroup>(new PwGroupEqualityFromIdComparer());
public PwGroup Root;
public PwDatabase KpDatabase;
public IOConnectionInfo Ioc { get { return KpDatabase.IOConnectionInfo; } }
public IOConnectionInfo Ioc
{
get
{
return KpDatabase == null ? null : KpDatabase.IOConnectionInfo;
}
}
public string LastFileVersion;
public SearchDbHelper SearchHelper;

View File

@@ -54,14 +54,15 @@ namespace keepass2android
public override void Run ()
{
if (! _dontSave) {
if (!_dontSave)
{
try
{
StatusLogger.UpdateMessage(UiStringKey.saving_database);
IOConnectionInfo ioc = _app.GetDb().Ioc;
IFileStorage fileStorage = _app.GetFileStorage(ioc);
if ((!_app.GetBooleanPreference(PreferenceKey.CheckForFileChangesOnSave))
|| (_app.GetDb().KpDatabase.HashOfFileOnDisk == null)) //first time saving
{
@@ -70,42 +71,44 @@ namespace keepass2android
return;
}
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:
{
//ask user...
_app.AskYesNoCancel(UiStringKey.TitleSyncQuestion, UiStringKey.MessageSyncQuestion,
_app.AskYesNoCancel(UiStringKey.TitleSyncQuestion, UiStringKey.MessageSyncQuestion,
UiStringKey.YesSynchronize,
UiStringKey.NoOverwrite,
//yes = sync
(sender, args) =>
{
Action runHandler = () =>
{
//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
//small.
MergeIn(fileStorage, ioc);
PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true);
};
RunInWorkerThread(runHandler);
},
{
Action runHandler = () =>
{
//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
//small.
MergeIn(fileStorage, ioc);
PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true);
};
RunInWorkerThread(runHandler);
},
//no = overwrite
(sender, args) =>
{
RunInWorkerThread( () =>
{
PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true);
});
},
{
RunInWorkerThread(() =>
{
PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true);
});
},
//cancel
(sender, args) =>
{
RunInWorkerThread(() => Finish(false));
},
{
RunInWorkerThread(() => Finish(false));
},
_ctx
);
}
@@ -114,8 +117,10 @@ namespace keepass2android
PerformSaveWithoutCheck(fileStorage, ioc);
Finish(true);
}
} catch (Exception e) {
}
catch (Exception e)
{
/* TODO KPDesktop:
* catch(Exception exSave)
{
@@ -123,12 +128,15 @@ namespace keepass2android
bSuccess = false;
}
*/
Kp2aLog.Log("Error while saving: "+e.ToString());
Finish (false, e.Message);
Kp2aLog.Log("Error while saving: " + e.ToString());
Finish(false, e.Message);
return;
}
}
}
else
{
Finish(true);
}
}