[KOE-14] Initial version of patcher. Does all the patching, but somehow doesn't work

This commit is contained in:
Patrick Simpson 2017-01-18 14:06:18 +01:00
parent 6d135c0ddc
commit 9e05601fe9
6 changed files with 106 additions and 7 deletions

View File

@ -237,7 +237,7 @@
<Compile Include="Controls\KUITask.cs" />
<Compile Include="Controls\KUIUtil.cs" />
<Compile Include="DebugOptions.cs" />
<Compile Include="Features\Contacts\FeatureContacts.cs" />
<Compile Include="Features\SecondaryContacts\FeatureSecondaryContacts.cs" />
<Compile Include="Features\DebugSupport\AboutDialog.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -33,6 +33,7 @@ namespace Acacia.Features
typeof(FreeBusy.FeatureFreeBusy),
typeof(GAB.FeatureGAB),
typeof(Notes.FeatureNotes),
typeof(SecondaryContacts.FeatureSecondaryContacts),
typeof(SendAs.FeatureSendAs),
typeof(DebugSupport.FeatureDebugSupport)
};

View File

@ -84,7 +84,7 @@ namespace Acacia.Features.Notes
PatchIfConfirmed(folder);
}
private bool IsNotesFolder(OutlookConstants.SyncType type)
private bool IsNotesFolder(OutlookConstants.SyncType? type)
{
return type == OutlookConstants.SyncType.Note || type == OutlookConstants.SyncType.UserNote;
}
@ -128,7 +128,7 @@ namespace Acacia.Features.Notes
return;
// Patch if needed
OutlookConstants.SyncType type = FolderUtils.GetFolderSyncType(folder);
OutlookConstants.SyncType? type = FolderUtils.GetFolderSyncType(folder);
Logger.Instance.Trace(this, "Notes folder type: {0}", type);
if (IsNotesFolder(type))
{
@ -174,7 +174,7 @@ namespace Acacia.Features.Notes
return;
// Unpatch if needed
OutlookConstants.SyncType type = FolderUtils.GetFolderSyncType(folder, true);
OutlookConstants.SyncType? type = FolderUtils.GetFolderSyncType(folder, true);
Logger.Instance.Trace(this, "Notes folder type: {0}", type);
// Unpatch only if the original type is a notes folder, but the current type isn't
if (IsNotesFolder(type) && !IsNotesFolder(FolderUtils.GetFolderSyncType(folder)))

View File

@ -0,0 +1,93 @@
/// Copyright 2017 Kopano b.v.
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License, version 3,
/// as published by the Free Software Foundation.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
/// GNU Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program.If not, see<http://www.gnu.org/licenses/>.
///
/// Consult LICENSE file for details
using Acacia.Stubs;
using Acacia.Stubs.OutlookWrappers;
using Acacia.Utils;
using Acacia.ZPush;
using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Acacia.DebugOptions;
namespace Acacia.Features.SecondaryContacts
{
[AcaciaOption("Provides the possibility to synchronise multiple contacts folders to and from a Z-Push server.")]
public class FeatureSecondaryContacts : Feature
{
private const string SUFFIX_CONTACTS = "\x200B";
private class FolderRegistrationSecondaryContacts : FolderRegistration
{
public FolderRegistrationSecondaryContacts(Feature feature) : base(feature)
{
}
public override bool IsApplicable(IFolder folder)
{
// Check the sync type
if (FolderUtils.GetFolderSyncType(folder) != OutlookConstants.SyncType.Unknown)
return false;
// Check the hidden suffix
if (!folder.Name.EndsWith(SUFFIX_CONTACTS))
return false;
Logger.Instance.Debug(this.Feature, "CONTACTS: {0} - {1}", folder.Name, StringUtil.BytesToHex(Encoding.UTF8.GetBytes(folder.Name)));
return true;
}
}
public FeatureSecondaryContacts()
{
}
public override void Startup()
{
Watcher.WatchFolder(new FolderRegistrationSecondaryContacts(this),
OnUnpatchedFolderDiscovered);
}
private void OnUnpatchedFolderDiscovered(IFolder folder)
{
string strippedName = folder.Name.StripSuffix(SUFFIX_CONTACTS);
// Update the properties
folder.SetProperties(new string[]
{
OutlookConstants.PR_EAS_SYNCTYPE,
OutlookConstants.PR_CONTAINER_CLASS,
OutlookConstants.PR_EAS_NAME,
OutlookConstants.PR_DISPLAY_NAME,
OutlookConstants.PR_EAS_SYNC1,
OutlookConstants.PR_EAS_SYNC2
}, new object[]
{
(int)OutlookConstants.SyncType.UserContact,
"IPF.Contact",
strippedName,
strippedName,
true, true
});
}
}
}

View File

@ -83,6 +83,8 @@ namespace Acacia
public const string PR_SUBJECT = PROP + "0037" + PT_UNICODE;
public const string PR_CONTAINER_CLASS = PROP + "3613" + PT_UNICODE;
#endregion
#region Email specific
@ -120,6 +122,7 @@ namespace Acacia
public const string PR_EAS_SYNCTYPE = PROP + "6A1A" + PT_LONG;
public const string PR_EAS_SYNC2 = PROP + "6A1D" + PT_BOOLEAN;
public const string PR_NET_FOLDER_FLAGS = PROP + "36DE" + PT_LONG;
public const string PR_EAS_NAME = PROP + "6915" + PT_UNICODE;
public enum SyncType
{

View File

@ -28,17 +28,19 @@ namespace Acacia.Utils
{
public static class FolderUtils
{
public static OutlookConstants.SyncType GetFolderSyncType(IFolder folder, bool orig = false)
public static OutlookConstants.SyncType? GetFolderSyncType(IFolder folder, bool orig = false)
{
if (orig)
{
string type = (string)folder.GetProperty(OutlookConstants.PR_EAS_SYNCTYPE_ORIG);
if (string.IsNullOrEmpty(type))
return null;
return (OutlookConstants.SyncType)int.Parse(type);
}
else
{
int type = (int)folder.GetProperty(OutlookConstants.PR_EAS_SYNCTYPE);
return (OutlookConstants.SyncType)type;
int? type = (int?)folder.GetProperty(OutlookConstants.PR_EAS_SYNCTYPE);
return (OutlookConstants.SyncType?)type;
}
}