Compare commits

...

4 Commits

Author SHA1 Message Date
duffyduck 499763d81f Release v0.0.0.6 2026-04-03 11:57:58 +02:00
duffyduck 9aa6ccb224 Fix Outlook COM connection: use Activator and clear error message
- Try GetActiveObject first, then Activator.CreateInstance as fallback
- Use Type.GetTypeFromProgID for version-independent COM activation
- Clear error message explaining possible causes including New Outlook
- NuGet Interop v15 is fine - it's the assembly version, works with
  all Outlook versions (2013-2024) via COM interface compatibility

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 11:56:34 +02:00
duffyduck 235960f450 Release v0.0.0.5 2026-04-03 11:53:31 +02:00
duffyduck 9298c3c287 Fix Outlook folder discovery to find all contact folders
- Scan all stores recursively instead of only the default folder
- Properly release COM objects to avoid leaks
- Better error handling with debug output per store/folder
- Show error message if Outlook is not reachable
- Fallback to default contacts folder if recursive scan finds nothing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 11:52:44 +02:00
5 changed files with 73 additions and 42 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php) ; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php)
#define MyAppName "Starface Outlook Sync" #define MyAppName "Starface Outlook Sync"
#define MyAppVersion "0.0.0.4" #define MyAppVersion "0.0.0.6"
#define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation" #define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation"
#define MyAppURL "https://www.hacker-net.de" #define MyAppURL "https://www.hacker-net.de"
#define MyAppExeName "StarfaceOutlookSync.exe" #define MyAppExeName "StarfaceOutlookSync.exe"
@@ -26,20 +26,35 @@ namespace StarfaceOutlookSync.Services
{ {
if (_outlookApp != null) return _outlookApp; if (_outlookApp != null) return _outlookApp;
// Versuch 1: Laufende Outlook-Instanz finden
try try
{ {
// Versuche laufende Outlook-Instanz zu finden
_outlookApp = (Outlook.Application)GetActiveComObject("Outlook.Application"); _outlookApp = (Outlook.Application)GetActiveComObject("Outlook.Application");
_weStartedOutlook = false; _weStartedOutlook = false;
return _outlookApp;
} }
catch catch { }
{
// Outlook starten falls nicht laufend
_outlookApp = new Outlook.Application();
_weStartedOutlook = true;
}
return _outlookApp; // Versuch 2: Outlook per COM starten
try
{
var outlookType = Type.GetTypeFromProgID("Outlook.Application");
if (outlookType != null)
{
_outlookApp = (Outlook.Application)Activator.CreateInstance(outlookType);
_weStartedOutlook = true;
return _outlookApp;
}
}
catch { }
throw new InvalidOperationException(
"Outlook Classic konnte nicht gefunden werden.\n\n" +
"Moegliche Ursachen:\n" +
"- Outlook Classic ist nicht installiert\n" +
"- Outlook Classic ist nicht gestartet\n" +
"- Das neue Outlook wird verwendet (wird noch nicht unterstuetzt)\n\n" +
"Bitte Outlook Classic starten und erneut versuchen.");
} }
public List<string> GetContactFolderPaths() public List<string> GetContactFolderPaths()
@@ -50,20 +65,29 @@ namespace StarfaceOutlookSync.Services
var app = GetOutlookApp(); var app = GetOutlookApp();
var ns = app.GetNamespace("MAPI"); var ns = app.GetNamespace("MAPI");
// Standard-Kontaktordner // Alle Stores durchgehen (jedes Konto, jede PST-Datei etc.)
var defaultFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
folders.Add(defaultFolder.FolderPath);
// Unterordner
AddSubFolders(defaultFolder, folders);
// Weitere Kontaktordner in anderen Stores
foreach (Outlook.Store store in ns.Stores) foreach (Outlook.Store store in ns.Stores)
{ {
try try
{ {
var rootFolder = store.GetRootFolder(); var rootFolder = store.GetRootFolder();
FindContactFolders(rootFolder, folders); FindContactFoldersRecursive(rootFolder, folders);
Marshal.ReleaseComObject(rootFolder);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error scanning store '{store.DisplayName}': {ex.Message}");
}
}
// Falls nichts gefunden, Standard-Kontaktordner als Fallback
if (folders.Count == 0)
{
try
{
var defaultFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
folders.Add(defaultFolder.FolderPath);
Marshal.ReleaseComObject(defaultFolder);
} }
catch { } catch { }
} }
@@ -78,30 +102,34 @@ namespace StarfaceOutlookSync.Services
return folders; return folders;
} }
private void AddSubFolders(Outlook.MAPIFolder folder, List<string> paths) private void FindContactFoldersRecursive(Outlook.MAPIFolder folder, List<string> paths)
{ {
foreach (Outlook.MAPIFolder sub in folder.Folders) try
{ {
if (sub.DefaultItemType == Outlook.OlItemType.olContactItem) // Kontaktordner erkennen: DefaultItemType ODER Ordnername enthaelt "Kontakt"/"Contact"
if (folder.DefaultItemType == Outlook.OlItemType.olContactItem)
{ {
if (!paths.Contains(sub.FolderPath)) if (!paths.Contains(folder.FolderPath))
paths.Add(sub.FolderPath); paths.Add(folder.FolderPath);
AddSubFolders(sub, paths); }
// Alle Unterordner durchsuchen
foreach (Outlook.MAPIFolder sub in folder.Folders)
{
try
{
FindContactFoldersRecursive(sub, paths);
}
catch { }
finally
{
Marshal.ReleaseComObject(sub);
}
} }
} }
} catch (Exception ex)
private void FindContactFolders(Outlook.MAPIFolder folder, List<string> paths)
{
if (folder.DefaultItemType == Outlook.OlItemType.olContactItem)
{ {
if (!paths.Contains(folder.FolderPath)) System.Diagnostics.Debug.WriteLine($"Error scanning folder '{folder.Name}': {ex.Message}");
paths.Add(folder.FolderPath);
}
foreach (Outlook.MAPIFolder sub in folder.Folders)
{
FindContactFolders(sub, paths);
} }
} }
@@ -7,9 +7,9 @@
<AssemblyTitle>Starface Outlook Sync</AssemblyTitle> <AssemblyTitle>Starface Outlook Sync</AssemblyTitle>
<Company>HackerSoft - Hacker-Net Telekommunikation</Company> <Company>HackerSoft - Hacker-Net Telekommunikation</Company>
<Product>Starface Outlook Sync</Product> <Product>Starface Outlook Sync</Product>
<Version>0.0.0.4</Version> <Version>0.0.0.6</Version>
<AssemblyVersion>0.0.0.4</AssemblyVersion> <AssemblyVersion>0.0.0.6</AssemblyVersion>
<FileVersion>0.0.0.4</FileVersion> <FileVersion>0.0.0.6</FileVersion>
<Description>Synchronisiert Outlook-Kontakte mit Starface Telefonanlage</Description> <Description>Synchronisiert Outlook-Kontakte mit Starface Telefonanlage</Description>
<Copyright>Stefan Hacker - HackerSoft</Copyright> <Copyright>Stefan Hacker - HackerSoft</Copyright>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
+1 -1
View File
@@ -27,7 +27,7 @@ namespace StarfaceOutlookSync.UI
var lblVersion = new Label var lblVersion = new Label
{ {
Text = "Version 0.0.0.4", Text = "Version 0.0.0.6",
Left = 0, Top = 56, Width = 340, Height = 20, Left = 0, Top = 56, Width = 340, Height = 20,
TextAlign = ContentAlignment.MiddleCenter, TextAlign = ContentAlignment.MiddleCenter,
ForeColor = Color.Gray ForeColor = Color.Gray
@@ -142,9 +142,12 @@ namespace StarfaceOutlookSync.UI
_outlookFolderPaths = outlook.GetContactFolderPaths(); _outlookFolderPaths = outlook.GetContactFolderPaths();
} }
} }
catch catch (Exception ex)
{ {
_outlookFolderPaths = new List<string> { "\\\\Kontakte" }; MessageBox.Show(
$"Outlook-Kontaktordner konnten nicht geladen werden:\n{ex.Message}\n\nIst Outlook gestartet?",
"Outlook-Verbindung", MessageBoxButtons.OK, MessageBoxIcon.Warning);
_outlookFolderPaths = new List<string>();
} }
// Bestehende Werte laden // Bestehende Werte laden