Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3092150d3a | |||
| 163dc17b49 | |||
| b7cc335184 | |||
| a19a39b7d2 | |||
| 6349424007 | |||
| 7ffaddc77f | |||
| 9007e2a9b5 | |||
| 0eadb2274e | |||
| a676e064c4 | |||
| 39ec176b16 | |||
| 39be854a4a | |||
| 724beba34a | |||
| 65d3e911d0 | |||
| ab9c16c69a | |||
| 3e22a40e17 | |||
| 36aca2c04d | |||
| 4f56f28ccb |
+1
-1
@@ -2,7 +2,7 @@
|
||||
; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php)
|
||||
|
||||
#define MyAppName "Starface Outlook Sync"
|
||||
#define MyAppVersion "0.0.0.14"
|
||||
#define MyAppVersion "0.0.0.20"
|
||||
#define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation"
|
||||
#define MyAppURL "https://www.hacker-net.de"
|
||||
#define MyAppExeName "StarfaceOutlookSync.exe"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace StarfaceOutlookSync.Models
|
||||
@@ -7,6 +8,8 @@ namespace StarfaceOutlookSync.Models
|
||||
public class UserSettings
|
||||
{
|
||||
public bool StartMinimized { get; set; } = false;
|
||||
public bool SyncOnStart { get; set; } = false;
|
||||
public bool AutoAcceptOutlookPrompt { get; set; } = false;
|
||||
|
||||
private static readonly string SettingsFile = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
@@ -32,6 +35,45 @@ namespace StarfaceOutlookSync.Models
|
||||
File.WriteAllText(SettingsFile, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
}
|
||||
catch { }
|
||||
|
||||
ApplyOutlookSecuritySetting();
|
||||
}
|
||||
|
||||
public void ApplyOutlookSecuritySetting()
|
||||
{
|
||||
try
|
||||
{
|
||||
var regPath = @"Software\Policies\Microsoft\Office\16.0\Outlook\Security";
|
||||
|
||||
if (AutoAcceptOutlookPrompt)
|
||||
{
|
||||
// Alle Outlook Object Model Guard Prompts unterdruecken
|
||||
var key = Registry.CurrentUser.CreateSubKey(regPath);
|
||||
key.SetValue("ObjectModelGuard", 2, RegistryValueKind.DWord);
|
||||
key.SetValue("PromptOOMAddressBookAccess", 2, RegistryValueKind.DWord);
|
||||
key.SetValue("PromptOOMAddressInformationAccess", 2, RegistryValueKind.DWord);
|
||||
key.SetValue("AdminSecurityMode", 3, RegistryValueKind.DWord);
|
||||
key.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Zurueck auf Standard (Werte loeschen)
|
||||
try
|
||||
{
|
||||
var key = Registry.CurrentUser.OpenSubKey(regPath, true);
|
||||
if (key != null)
|
||||
{
|
||||
try { key.DeleteValue("ObjectModelGuard"); } catch { }
|
||||
try { key.DeleteValue("PromptOOMAddressBookAccess"); } catch { }
|
||||
try { key.DeleteValue("PromptOOMAddressInformationAccess"); } catch { }
|
||||
try { key.DeleteValue("AdminSecurityMode"); } catch { }
|
||||
key.Close();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,29 +394,40 @@ namespace StarfaceOutlookSync.Services
|
||||
}
|
||||
}
|
||||
|
||||
private static string SafeGet(dynamic ci, string property)
|
||||
{
|
||||
try
|
||||
{
|
||||
object val = ci.GetType().InvokeMember(property,
|
||||
System.Reflection.BindingFlags.GetProperty, null, ci, null);
|
||||
return val?.ToString() ?? "";
|
||||
}
|
||||
catch { return ""; }
|
||||
}
|
||||
|
||||
private UnifiedContact MapFromOutlook(dynamic ci)
|
||||
{
|
||||
return new UnifiedContact
|
||||
{
|
||||
OutlookEntryId = (string)(ci.EntryID ?? ""),
|
||||
FirstName = (string)(ci.FirstName ?? ""),
|
||||
LastName = (string)(ci.LastName ?? ""),
|
||||
Company = (string)(ci.CompanyName ?? ""),
|
||||
JobTitle = (string)(ci.JobTitle ?? ""),
|
||||
Email = (string)(ci.Email1Address ?? ""),
|
||||
EmailSecondary = (string)(ci.Email2Address ?? ""),
|
||||
PhoneWork = (string)(ci.BusinessTelephoneNumber ?? ""),
|
||||
PhoneMobile = (string)(ci.MobileTelephoneNumber ?? ""),
|
||||
PhoneHome = (string)(ci.HomeTelephoneNumber ?? ""),
|
||||
Fax = (string)(ci.BusinessFaxNumber ?? ""),
|
||||
Street = (string)(ci.BusinessAddressStreet ?? ""),
|
||||
City = (string)(ci.BusinessAddressCity ?? ""),
|
||||
PostalCode = (string)(ci.BusinessAddressPostalCode ?? ""),
|
||||
State = (string)(ci.BusinessAddressState ?? ""),
|
||||
Country = (string)(ci.BusinessAddressCountry ?? ""),
|
||||
Website = (string)(ci.WebPage ?? ""),
|
||||
Notes = (string)(ci.Body ?? ""),
|
||||
Salutation = (string)(ci.Title ?? ""),
|
||||
OutlookEntryId = SafeGet(ci, "EntryID"),
|
||||
FirstName = SafeGet(ci, "FirstName"),
|
||||
LastName = SafeGet(ci, "LastName"),
|
||||
Company = SafeGet(ci, "CompanyName"),
|
||||
JobTitle = SafeGet(ci, "JobTitle"),
|
||||
Email = SafeGet(ci, "Email1Address"),
|
||||
EmailSecondary = SafeGet(ci, "Email2Address"),
|
||||
PhoneWork = SafeGet(ci, "BusinessTelephoneNumber"),
|
||||
PhoneMobile = SafeGet(ci, "MobileTelephoneNumber"),
|
||||
PhoneHome = SafeGet(ci, "HomeTelephoneNumber"),
|
||||
Fax = SafeGet(ci, "BusinessFaxNumber"),
|
||||
Street = SafeGet(ci, "BusinessAddressStreet"),
|
||||
City = SafeGet(ci, "BusinessAddressCity"),
|
||||
PostalCode = SafeGet(ci, "BusinessAddressPostalCode"),
|
||||
State = SafeGet(ci, "BusinessAddressState"),
|
||||
Country = SafeGet(ci, "BusinessAddressCountry"),
|
||||
Website = SafeGet(ci, "WebPage"),
|
||||
Notes = SafeGet(ci, "Body"),
|
||||
Salutation = SafeGet(ci, "Title"),
|
||||
Birthday = GetBirthdayString(ci)
|
||||
};
|
||||
}
|
||||
@@ -425,8 +436,9 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime bday = ci.Birthday;
|
||||
if (bday.Year > 1900 && bday != DateTime.MinValue)
|
||||
object val = ci.GetType().InvokeMember("Birthday",
|
||||
System.Reflection.BindingFlags.GetProperty, null, ci, null);
|
||||
if (val is DateTime bday && bday.Year > 1900 && bday != DateTime.MinValue)
|
||||
return bday.ToString("yyyy-MM-dd");
|
||||
}
|
||||
catch { }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
@@ -115,43 +116,63 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
var books = new List<StarfaceAddressBook>();
|
||||
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "central",
|
||||
Name = "Zentrales Adressbuch"
|
||||
});
|
||||
|
||||
var userId = await GetCurrentUserIdAsync();
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "user",
|
||||
UserId = userId,
|
||||
Name = "Persoenliches Adressbuch"
|
||||
});
|
||||
}
|
||||
|
||||
// Tags als virtuelle Adressbuecher
|
||||
// Alle Tags laden - die Starface nutzt Tags als Adressbuch-Zuordnung
|
||||
var allTags = new JArray();
|
||||
try
|
||||
{
|
||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts/tags");
|
||||
if (resp.IsSuccessStatusCode)
|
||||
{
|
||||
var tags = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "tag",
|
||||
TagId = tag["id"]?.ToString() ?? "",
|
||||
Name = $"Tag: {tag["name"]}"
|
||||
});
|
||||
}
|
||||
allTags = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
||||
OnDebug?.Invoke($"Gefundene Tags: {allTags.Count}");
|
||||
foreach (var t in allTags)
|
||||
OnDebug?.Invoke($" Tag: {t["name"]} (id: {t["id"]}, alias: {t["alias"]}, owner: {t["owner"]})");
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Zentrales Adressbuch (folder/all)
|
||||
var allTag = allTags.FirstOrDefault(t => t["name"]?.ToString() == "folder/all"
|
||||
|| t["alias"]?.ToString()?.Contains("folder.all") == true);
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "central",
|
||||
TagId = allTag?["id"]?.ToString() ?? "",
|
||||
Name = "Zentrales Adressbuch"
|
||||
});
|
||||
|
||||
// Persoenliches Adressbuch (folder/private mit owner = userId)
|
||||
var userId = await GetCurrentUserIdAsync();
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
var privateTag = allTags.FirstOrDefault(t =>
|
||||
(t["name"]?.ToString() == "folder/private" || t["alias"]?.ToString()?.Contains("folder.private") == true)
|
||||
&& t["owner"]?.ToString() == userId);
|
||||
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "user",
|
||||
UserId = userId,
|
||||
TagId = privateTag?["id"]?.ToString() ?? "",
|
||||
Name = "Persoenliches Adressbuch"
|
||||
});
|
||||
}
|
||||
|
||||
// Alle weiteren Tags als Adressbuecher anbieten
|
||||
foreach (var tag in allTags)
|
||||
{
|
||||
var tagName = tag["name"]?.ToString() ?? "";
|
||||
// folder/all und folder/private bereits oben erfasst
|
||||
if (tagName == "folder/all" || tagName == "folder/private") continue;
|
||||
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "tag",
|
||||
TagId = tag["id"]?.ToString() ?? "",
|
||||
Name = tagName
|
||||
});
|
||||
}
|
||||
|
||||
return books;
|
||||
}
|
||||
|
||||
@@ -248,6 +269,16 @@ namespace StarfaceOutlookSync.Services
|
||||
public async Task<UnifiedContact> CreateContactAsync(UnifiedContact contact, StarfaceAddressBook book)
|
||||
{
|
||||
var sfContact = MapToStarface(contact);
|
||||
|
||||
// Tag zuweisen - die Starface verlangt dass jeder Kontakt einem Tag zugeordnet ist
|
||||
if (!string.IsNullOrEmpty(book.TagId))
|
||||
{
|
||||
sfContact["tags"] = new JArray
|
||||
{
|
||||
new JObject { ["id"] = book.TagId }
|
||||
};
|
||||
}
|
||||
|
||||
var query = "";
|
||||
if (book.Type == "user" && !string.IsNullOrEmpty(book.UserId))
|
||||
query = $"?userId={book.UserId}";
|
||||
@@ -273,12 +304,27 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
var sfContact = MapToStarface(contact);
|
||||
sfContact["id"] = contactId;
|
||||
|
||||
// Tag beibehalten
|
||||
if (!string.IsNullOrEmpty(book.TagId))
|
||||
{
|
||||
sfContact["tags"] = new JArray { new JObject { ["id"] = book.TagId } };
|
||||
}
|
||||
|
||||
var query = "";
|
||||
if (book.Type == "user" && !string.IsNullOrEmpty(book.UserId))
|
||||
query = $"?userId={book.UserId}";
|
||||
|
||||
var content = new StringContent(sfContact.ToString(), Encoding.UTF8, "application/json");
|
||||
var body = sfContact.ToString();
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
var resp = await _http.PutAsync($"{_baseUrl}/contacts/{contactId}{query}", content);
|
||||
|
||||
if (!resp.IsSuccessStatusCode)
|
||||
{
|
||||
var respBody = await resp.Content.ReadAsStringAsync();
|
||||
OnDebug?.Invoke($"PUT /contacts/{contactId} fehlgeschlagen: {(int)resp.StatusCode}\n{respBody}");
|
||||
}
|
||||
|
||||
return resp.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,61 +17,94 @@ namespace StarfaceOutlookSync.Services
|
||||
|
||||
/// <summary>
|
||||
/// Findet einen passenden Kontakt in der Kandidatenliste.
|
||||
/// Matching-Reihenfolge: E-Mail, dann Vorname+Nachname+Firma, dann Vorname+Nachname.
|
||||
/// Strenges Matching: Felder die auf einer Seite gefuellt sind muessen
|
||||
/// auf der anderen auch gefuellt (und gleich) sein.
|
||||
/// Ein leeres Feld auf einer Seite und ein gefuelltes auf der anderen
|
||||
/// bedeutet: verschiedene Kontakte.
|
||||
/// </summary>
|
||||
private static UnifiedContact FindMatch(UnifiedContact contact, List<UnifiedContact> candidates)
|
||||
{
|
||||
if (candidates == null || candidates.Count == 0) return null;
|
||||
|
||||
// 1. Exakte E-Mail
|
||||
if (!string.IsNullOrEmpty(contact.Email))
|
||||
foreach (var c in candidates)
|
||||
{
|
||||
var byEmail = candidates.FirstOrDefault(c =>
|
||||
!string.IsNullOrEmpty(c.Email) &&
|
||||
c.Email.Equals(contact.Email, StringComparison.OrdinalIgnoreCase));
|
||||
if (byEmail != null) return byEmail;
|
||||
}
|
||||
|
||||
// 2. Vorname + Nachname + Firma (staerkstes Match ohne E-Mail)
|
||||
if ((!string.IsNullOrEmpty(contact.FirstName) || !string.IsNullOrEmpty(contact.LastName))
|
||||
&& !string.IsNullOrEmpty(contact.Company))
|
||||
{
|
||||
var byNameCompany = candidates.FirstOrDefault(c =>
|
||||
c.FirstName.Equals(contact.FirstName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.LastName.Equals(contact.LastName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.Company.Equals(contact.Company, StringComparison.OrdinalIgnoreCase));
|
||||
if (byNameCompany != null) return byNameCompany;
|
||||
}
|
||||
|
||||
// 3. Vorname + Nachname (ohne Firma)
|
||||
if (!string.IsNullOrEmpty(contact.FirstName) || !string.IsNullOrEmpty(contact.LastName))
|
||||
{
|
||||
var byName = candidates.FirstOrDefault(c =>
|
||||
c.FirstName.Equals(contact.FirstName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.LastName.Equals(contact.LastName, StringComparison.OrdinalIgnoreCase) &&
|
||||
(!string.IsNullOrEmpty(c.FirstName) || !string.IsNullOrEmpty(c.LastName)));
|
||||
if (byName != null) return byName;
|
||||
}
|
||||
|
||||
// 4. Telefonnummer (Buero oder Mobil)
|
||||
if (!string.IsNullOrEmpty(contact.PhoneWork))
|
||||
{
|
||||
var byPhone = candidates.FirstOrDefault(c =>
|
||||
!string.IsNullOrEmpty(c.PhoneWork) &&
|
||||
NormalizePhone(c.PhoneWork) == NormalizePhone(contact.PhoneWork));
|
||||
if (byPhone != null) return byPhone;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(contact.PhoneMobile))
|
||||
{
|
||||
var byMobile = candidates.FirstOrDefault(c =>
|
||||
!string.IsNullOrEmpty(c.PhoneMobile) &&
|
||||
NormalizePhone(c.PhoneMobile) == NormalizePhone(contact.PhoneMobile));
|
||||
if (byMobile != null) return byMobile;
|
||||
if (IsMatch(contact, c))
|
||||
return c;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsMatch(UnifiedContact a, UnifiedContact b)
|
||||
{
|
||||
// Mindestens ein identifizierendes Feld muss vorhanden sein
|
||||
bool hasName = !string.IsNullOrEmpty(a.FirstName) || !string.IsNullOrEmpty(a.LastName);
|
||||
bool hasEmail = !string.IsNullOrEmpty(a.Email);
|
||||
bool hasPhone = !string.IsNullOrEmpty(a.PhoneWork) || !string.IsNullOrEmpty(a.PhoneMobile);
|
||||
|
||||
if (!hasName && !hasEmail && !hasPhone) return false;
|
||||
|
||||
// E-Mail: wenn auf beiden Seiten vorhanden, muss sie gleich sein
|
||||
// Wenn nur auf einer Seite vorhanden -> kein Match
|
||||
if (!FieldsCompatible(a.Email, b.Email)) return false;
|
||||
|
||||
// Name: wenn auf einer Seite vorhanden, muss er gleich sein
|
||||
if (!FieldsCompatible(a.FirstName, b.FirstName)) return false;
|
||||
if (!FieldsCompatible(a.LastName, b.LastName)) return false;
|
||||
|
||||
// Firma: wenn auf einer Seite vorhanden, muss sie gleich sein
|
||||
// Leere Firma vs. gefuellte Firma = verschiedene Kontakte
|
||||
if (!FieldsCompatible(a.Company, b.Company)) return false;
|
||||
|
||||
// Telefon/Fax: wenn auf einer Seite vorhanden, muss es gleich sein
|
||||
if (!PhoneFieldsCompatible(a.PhoneWork, b.PhoneWork)) return false;
|
||||
if (!PhoneFieldsCompatible(a.PhoneMobile, b.PhoneMobile)) return false;
|
||||
if (!PhoneFieldsCompatible(a.PhoneHome, b.PhoneHome)) return false;
|
||||
if (!PhoneFieldsCompatible(a.Fax, b.Fax)) return false;
|
||||
|
||||
// Mindestens ein starkes Match muss vorhanden sein
|
||||
bool emailMatch = !string.IsNullOrEmpty(a.Email) && !string.IsNullOrEmpty(b.Email)
|
||||
&& a.Email.Equals(b.Email, StringComparison.OrdinalIgnoreCase);
|
||||
bool nameMatch = hasName
|
||||
&& a.FirstName.Equals(b.FirstName, StringComparison.OrdinalIgnoreCase)
|
||||
&& a.LastName.Equals(b.LastName, StringComparison.OrdinalIgnoreCase)
|
||||
&& (!string.IsNullOrEmpty(a.FirstName) || !string.IsNullOrEmpty(a.LastName));
|
||||
bool phoneMatch = (!string.IsNullOrEmpty(a.PhoneWork) && !string.IsNullOrEmpty(b.PhoneWork)
|
||||
&& NormalizePhone(a.PhoneWork) == NormalizePhone(b.PhoneWork))
|
||||
|| (!string.IsNullOrEmpty(a.Fax) && !string.IsNullOrEmpty(b.Fax)
|
||||
&& NormalizePhone(a.Fax) == NormalizePhone(b.Fax));
|
||||
bool companyMatch = !string.IsNullOrEmpty(a.Company) && !string.IsNullOrEmpty(b.Company)
|
||||
&& a.Company.Equals(b.Company, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// Email oder Name reicht. Telefon/Fax nur mit Firma zusammen.
|
||||
return emailMatch || nameMatch || (phoneMatch && companyMatch) || (companyMatch && phoneMatch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prueft ob zwei Felder kompatibel sind.
|
||||
/// Beide leer = kompatibel. Beide gleich = kompatibel.
|
||||
/// Eins leer, eins gefuellt = NICHT kompatibel (verschiedene Kontakte).
|
||||
/// </summary>
|
||||
private static bool FieldsCompatible(string a, string b)
|
||||
{
|
||||
bool aEmpty = string.IsNullOrEmpty(a);
|
||||
bool bEmpty = string.IsNullOrEmpty(b);
|
||||
|
||||
if (aEmpty && bEmpty) return true;
|
||||
if (aEmpty != bEmpty) return false; // Einer leer, anderer nicht
|
||||
return a.Equals(b, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static bool PhoneFieldsCompatible(string a, string b)
|
||||
{
|
||||
bool aEmpty = string.IsNullOrEmpty(a);
|
||||
bool bEmpty = string.IsNullOrEmpty(b);
|
||||
|
||||
if (aEmpty && bEmpty) return true;
|
||||
if (aEmpty != bEmpty) return false;
|
||||
return NormalizePhone(a) == NormalizePhone(b);
|
||||
}
|
||||
|
||||
private static string NormalizePhone(string phone)
|
||||
{
|
||||
if (string.IsNullOrEmpty(phone)) return "";
|
||||
@@ -144,6 +177,45 @@ namespace StarfaceOutlookSync.Services
|
||||
if (oc == null && sc == null)
|
||||
{
|
||||
// Beide Seiten geloescht -> Mapping entfernen
|
||||
Log($" Mapping verwaist (beide geloescht), entferne");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oc == null && sc != null)
|
||||
{
|
||||
// In Outlook geloescht -> in Starface auch loeschen
|
||||
if (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.OutlookToStarface)
|
||||
{
|
||||
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (OL->SF): {sc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Richtung erlaubt kein Loeschen -> Mapping behalten
|
||||
newMappings.Add(mapping);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oc != null && sc == null)
|
||||
{
|
||||
// In Starface geloescht -> in Outlook auch loeschen
|
||||
if (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.StarfaceToOutlook)
|
||||
{
|
||||
if (_outlookService.DeleteContact(mapping.OutlookEntryId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (SF->OL): {oc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Richtung erlaubt kein Loeschen -> Mapping behalten
|
||||
newMappings.Add(mapping);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<AssemblyTitle>Starface Outlook Sync</AssemblyTitle>
|
||||
<Company>HackerSoft - Hacker-Net Telekommunikation</Company>
|
||||
<Product>Starface Outlook Sync</Product>
|
||||
<Version>0.0.0.14</Version>
|
||||
<AssemblyVersion>0.0.0.14</AssemblyVersion>
|
||||
<FileVersion>0.0.0.14</FileVersion>
|
||||
<Version>0.0.0.20</Version>
|
||||
<AssemblyVersion>0.0.0.20</AssemblyVersion>
|
||||
<FileVersion>0.0.0.20</FileVersion>
|
||||
<Description>Synchronisiert Outlook-Kontakte mit Starface Telefonanlage</Description>
|
||||
<Copyright>Stefan Hacker - HackerSoft</Copyright>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace StarfaceOutlookSync.UI
|
||||
|
||||
var lblVersion = new Label
|
||||
{
|
||||
Text = "Version 0.0.0.14",
|
||||
Text = "Version 0.0.0.20",
|
||||
Left = 0, Top = 56, Width = 340, Height = 20,
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
ForeColor = Color.Gray
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Generiert das App-Icon programmatisch (Kontakt-Symbol mit Sync-Pfeilen).
|
||||
/// Kein externes ICO-File noetig.
|
||||
/// </summary>
|
||||
public static class AppIcon
|
||||
{
|
||||
private static Icon _icon;
|
||||
|
||||
public static Icon GetIcon()
|
||||
{
|
||||
if (_icon != null) return _icon;
|
||||
_icon = CreateIcon(32);
|
||||
return _icon;
|
||||
}
|
||||
|
||||
public static Icon GetSmallIcon()
|
||||
{
|
||||
return CreateIcon(16);
|
||||
}
|
||||
|
||||
private static Icon CreateIcon(int size)
|
||||
{
|
||||
using (var bmp = new Bitmap(size, size))
|
||||
using (var g = Graphics.FromImage(bmp))
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.Clear(Color.Transparent);
|
||||
|
||||
if (size >= 32)
|
||||
DrawIcon32(g);
|
||||
else
|
||||
DrawIcon16(g);
|
||||
|
||||
return Icon.FromHandle(bmp.GetHicon());
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawIcon32(Graphics g)
|
||||
{
|
||||
// Hintergrund: abgerundetes Quadrat
|
||||
using (var bgBrush = new SolidBrush(Color.FromArgb(0, 120, 212)))
|
||||
{
|
||||
FillRoundedRect(g, bgBrush, 0, 0, 31, 31, 6);
|
||||
}
|
||||
|
||||
// Person (Kopf)
|
||||
using (var whiteBrush = new SolidBrush(Color.White))
|
||||
{
|
||||
g.FillEllipse(whiteBrush, 11, 4, 10, 10);
|
||||
// Person (Koerper)
|
||||
g.FillPie(whiteBrush, 6, 14, 20, 18, 180, 180);
|
||||
}
|
||||
|
||||
// Sync-Pfeile unten rechts
|
||||
using (var arrowPen = new Pen(Color.FromArgb(120, 255, 120), 2f))
|
||||
{
|
||||
arrowPen.StartCap = LineCap.Round;
|
||||
arrowPen.EndCap = LineCap.ArrowAnchor;
|
||||
// Pfeil rechts
|
||||
g.DrawArc(arrowPen, 20, 22, 10, 8, 200, 140);
|
||||
arrowPen.Color = Color.FromArgb(255, 200, 80);
|
||||
// Pfeil links
|
||||
g.DrawArc(arrowPen, 20, 22, 10, 8, 20, 140);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawIcon16(Graphics g)
|
||||
{
|
||||
// Hintergrund
|
||||
using (var bgBrush = new SolidBrush(Color.FromArgb(0, 120, 212)))
|
||||
{
|
||||
FillRoundedRect(g, bgBrush, 0, 0, 15, 15, 3);
|
||||
}
|
||||
|
||||
// Person (vereinfacht)
|
||||
using (var whiteBrush = new SolidBrush(Color.White))
|
||||
{
|
||||
g.FillEllipse(whiteBrush, 4, 1, 7, 7);
|
||||
g.FillPie(whiteBrush, 2, 8, 12, 10, 180, 180);
|
||||
}
|
||||
|
||||
// Kleiner Sync-Indikator
|
||||
using (var dotBrush = new SolidBrush(Color.FromArgb(120, 255, 120)))
|
||||
{
|
||||
g.FillEllipse(dotBrush, 11, 11, 4, 4);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FillRoundedRect(Graphics g, Brush brush, int x, int y, int w, int h, int r)
|
||||
{
|
||||
using (var path = new GraphicsPath())
|
||||
{
|
||||
path.AddArc(x, y, r * 2, r * 2, 180, 90);
|
||||
path.AddArc(x + w - r * 2, y, r * 2, r * 2, 270, 90);
|
||||
path.AddArc(x + w - r * 2, y + h - r * 2, r * 2, r * 2, 0, 90);
|
||||
path.AddArc(x, y + h - r * 2, r * 2, r * 2, 90, 90);
|
||||
path.CloseFigure();
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ namespace StarfaceOutlookSync.UI
|
||||
private StatusStrip _statusBar;
|
||||
private ToolStripStatusLabel _statusLabel;
|
||||
private Timer _autoSyncTimer;
|
||||
private volatile bool _syncRunning = false;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@@ -30,14 +31,31 @@ namespace StarfaceOutlookSync.UI
|
||||
SetupAutoSync();
|
||||
RefreshProfileList();
|
||||
|
||||
// Minimiert starten falls in Einstellungen aktiviert
|
||||
// Einstellungen laden und anwenden
|
||||
var settings = UserSettings.Load();
|
||||
settings.ApplyOutlookSecuritySetting();
|
||||
|
||||
if (settings.StartMinimized)
|
||||
{
|
||||
WindowState = FormWindowState.Minimized;
|
||||
ShowInTaskbar = false;
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
// Beim Start automatisch synchronisieren
|
||||
if (settings.SyncOnStart)
|
||||
{
|
||||
_ = SyncAllProfiles();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SyncAllProfiles()
|
||||
{
|
||||
var profiles = _profileManager.GetProfiles().Where(p => p.Enabled).ToList();
|
||||
foreach (var profile in profiles)
|
||||
{
|
||||
await RunSync(profile);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetVisibleCore(bool value)
|
||||
@@ -62,6 +80,7 @@ namespace StarfaceOutlookSync.UI
|
||||
MinimumSize = new Size(500, 350);
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Font = new Font("Segoe UI", 9);
|
||||
Icon = AppIcon.GetIcon();
|
||||
|
||||
// Profil-Liste
|
||||
_profileList = new ListView
|
||||
@@ -124,10 +143,26 @@ namespace StarfaceOutlookSync.UI
|
||||
private void SetupTrayIcon()
|
||||
{
|
||||
_trayMenu = new ContextMenuStrip();
|
||||
|
||||
_trayIcon = new NotifyIcon
|
||||
{
|
||||
Text = "Starface Kontakt-Sync",
|
||||
Icon = AppIcon.GetSmallIcon(),
|
||||
ContextMenuStrip = _trayMenu,
|
||||
Visible = true
|
||||
};
|
||||
|
||||
_trayIcon.DoubleClick += (s, e) => ShowMainWindow();
|
||||
|
||||
UpdateTrayMenu();
|
||||
}
|
||||
|
||||
private void UpdateTrayMenu()
|
||||
{
|
||||
_trayMenu.Items.Clear();
|
||||
_trayMenu.Items.Add("Oeffnen", null, (s, e) => ShowMainWindow());
|
||||
_trayMenu.Items.Add("-");
|
||||
|
||||
// Schnell-Sync fuer jedes Profil
|
||||
var profiles = _profileManager.GetProfiles();
|
||||
foreach (var p in profiles.Where(p => p.Enabled))
|
||||
{
|
||||
@@ -141,17 +176,8 @@ namespace StarfaceOutlookSync.UI
|
||||
if (profiles.Any(p => p.Enabled))
|
||||
_trayMenu.Items.Add("-");
|
||||
|
||||
_trayMenu.Items.Add("Ueber", null, (s, e) => ShowAbout());
|
||||
_trayMenu.Items.Add("Beenden", null, (s, e) => ExitApplication());
|
||||
|
||||
_trayIcon = new NotifyIcon
|
||||
{
|
||||
Text = "Starface Kontakt-Sync",
|
||||
Icon = SystemIcons.Application, // Placeholder, wird durch eigenes Icon ersetzt
|
||||
ContextMenuStrip = _trayMenu,
|
||||
Visible = true
|
||||
};
|
||||
|
||||
_trayIcon.DoubleClick += (s, e) => ShowMainWindow();
|
||||
}
|
||||
|
||||
private void SetupAutoSync()
|
||||
@@ -219,7 +245,7 @@ namespace StarfaceOutlookSync.UI
|
||||
}
|
||||
|
||||
// Tray-Menu aktualisieren
|
||||
SetupTrayIcon();
|
||||
UpdateTrayMenu();
|
||||
}
|
||||
|
||||
private void NewProfile()
|
||||
@@ -311,6 +337,13 @@ namespace StarfaceOutlookSync.UI
|
||||
|
||||
private async Task RunSync(SyncProfile profile)
|
||||
{
|
||||
if (_syncRunning)
|
||||
{
|
||||
SetStatus("Sync laeuft bereits, bitte warten...");
|
||||
return;
|
||||
}
|
||||
|
||||
_syncRunning = true;
|
||||
try
|
||||
{
|
||||
SetStatus($"Synchronisiere '{profile.Name}'...");
|
||||
@@ -333,6 +366,10 @@ namespace StarfaceOutlookSync.UI
|
||||
ex.Message, ToolTipIcon.Error);
|
||||
SetStatus($"Fehler: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_syncRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetStatus(string text)
|
||||
|
||||
@@ -333,9 +333,23 @@ namespace StarfaceOutlookSync.UI
|
||||
};
|
||||
|
||||
if (_isNew)
|
||||
{
|
||||
_pm.AddProfile(profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wenn Adressbuch gewechselt wurde, Mappings zuruecksetzen
|
||||
if (_existingProfile.StarfaceAddressBook?.TagId != profile.StarfaceAddressBook?.TagId
|
||||
|| _existingProfile.StarfaceAddressBook?.Type != profile.StarfaceAddressBook?.Type)
|
||||
{
|
||||
_pm.SaveMappings(profile.Id, new List<SyncMapping>());
|
||||
profile.LastSync = "";
|
||||
MessageBox.Show(
|
||||
"Adressbuch wurde geaendert.\nSync-Zuordnungen wurden automatisch zurueckgesetzt.",
|
||||
"Adressbuch geaendert", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
_pm.UpdateProfile(profile);
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
public class SettingsForm : Form
|
||||
{
|
||||
private CheckBox _chkStartMinimized;
|
||||
private CheckBox _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook;
|
||||
private Button _btnSave, _btnCancel;
|
||||
private readonly UserSettings _settings;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace StarfaceOutlookSync.UI
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Text = "Einstellungen";
|
||||
Size = new Size(350, 180);
|
||||
Size = new Size(380, 250);
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
MaximizeBox = false;
|
||||
MinimizeBox = false;
|
||||
@@ -33,20 +33,34 @@ namespace StarfaceOutlookSync.UI
|
||||
Checked = _settings.StartMinimized
|
||||
};
|
||||
|
||||
_chkSyncOnStart = new CheckBox
|
||||
{
|
||||
Text = "Beim Start automatisch synchronisieren",
|
||||
Left = 20, Top = 52, AutoSize = true,
|
||||
Checked = _settings.SyncOnStart
|
||||
};
|
||||
|
||||
_chkAutoAcceptOutlook = new CheckBox
|
||||
{
|
||||
Text = "Outlook-Sicherheitsabfrage automatisch erlauben",
|
||||
Left = 20, Top = 80, AutoSize = true,
|
||||
Checked = _settings.AutoAcceptOutlookPrompt
|
||||
};
|
||||
|
||||
_btnSave = new Button
|
||||
{
|
||||
Text = "Speichern", Left = 80, Top = 100, Width = 85, Height = 28,
|
||||
Text = "Speichern", Left = 95, Top = 160, Width = 85, Height = 28,
|
||||
DialogResult = DialogResult.None
|
||||
};
|
||||
_btnSave.Click += (s, e) => Save();
|
||||
|
||||
_btnCancel = new Button
|
||||
{
|
||||
Text = "Abbrechen", Left = 174, Top = 100, Width = 85, Height = 28,
|
||||
Text = "Abbrechen", Left = 189, Top = 160, Width = 85, Height = 28,
|
||||
DialogResult = DialogResult.Cancel
|
||||
};
|
||||
|
||||
Controls.AddRange(new Control[] { _chkStartMinimized, _btnSave, _btnCancel });
|
||||
Controls.AddRange(new Control[] { _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook, _btnSave, _btnCancel });
|
||||
AcceptButton = _btnSave;
|
||||
CancelButton = _btnCancel;
|
||||
}
|
||||
@@ -54,6 +68,8 @@ namespace StarfaceOutlookSync.UI
|
||||
private void Save()
|
||||
{
|
||||
_settings.StartMinimized = _chkStartMinimized.Checked;
|
||||
_settings.SyncOnStart = _chkSyncOnStart.Checked;
|
||||
_settings.AutoAcceptOutlookPrompt = _chkAutoAcceptOutlook.Checked;
|
||||
_settings.Save();
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
Reference in New Issue
Block a user