Skip to content

Commit

Permalink
Quietly log failure to get CurrentUser if GAL blocked.
Browse files Browse the repository at this point in the history
Handle nulls in colour map.
Attempt saving again if settings.xml file locked when upgrading config.
  • Loading branch information
phw198 committed Feb 13, 2022
1 parent e0b66b4 commit 6551fa5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/Extensions/ColourPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public override void InitializeEditingControl(int rowIndex, object initialFormat
ctl.SelectedIndex = 0;
else {
String currentText = this.Value.ToString();
if (ctl.Items.Count == 0)
if (ctl.Items.Count == 0)
ctl.PopulateDropdownItems();
if (!string.IsNullOrEmpty(currentText)) this.Value = currentText;

Expand Down Expand Up @@ -289,7 +289,7 @@ protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.R
return;

foreach (GoogleOgcs.EventColour.Palette ci in Forms.ColourMap.GoogleComboBox.Items) {
if (ci.Name == this.Value.ToString()) {
if (ci.Name == this.Value?.ToString()) {
Brush boxBrush = new SolidBrush(ci.RgbValue);
Brush textBrush = SystemBrushes.WindowText;
Extensions.ColourCombobox.DrawComboboxItemColour(true, boxBrush, textBrush, this.Value.ToString(), graphics, cellBounds);
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/Forms/ColourMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void btOK_Click(object sender, EventArgs e) {
log.Fine("Storing colour mappings in Settings.");
profile.ColourMaps.Clear();
foreach (DataGridViewRow row in colourGridView.Rows) {
if (row.Cells["OutlookColour"].Value == null || row.Cells["OutlookColour"].Value.ToString().Trim() == "") continue;
if (string.IsNullOrEmpty(row.Cells["OutlookColour"].Value?.ToString()?.Trim()) || string.IsNullOrEmpty(row.Cells["GoogleColour"].Value?.ToString()?.Trim())) continue;
try {
profile.ColourMaps.Add(row.Cells["OutlookColour"].Value.ToString(), GoogleOgcs.EventColour.Palette.GetColourId(row.Cells["GoogleColour"].Value.ToString()));
} catch (System.ArgumentException ex) {
Expand Down Expand Up @@ -207,7 +207,7 @@ private void ddOutlookColour_SelectedIndexChanged(object sender, EventArgs e) {
ddGoogleColour.SelectedIndexChanged -= ddGoogleColour_SelectedIndexChanged;

foreach (DataGridViewRow row in colourGridView.Rows) {
if (row.Cells["OutlookColour"].Value.ToString() == ddOutlookColour.SelectedItem.Text && !string.IsNullOrEmpty(row.Cells["GoogleColour"].Value.ToString())) {
if (row.Cells["OutlookColour"].Value.ToString() == ddOutlookColour.SelectedItem.Text && !string.IsNullOrEmpty(row.Cells["GoogleColour"].Value?.ToString())) {
String colourId = GoogleOgcs.EventColour.Palette.GetColourId(row.Cells["GoogleColour"].Value.ToString());
ddGoogleColour.SelectedIndex = Convert.ToInt16(colourId);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ public NameSpace GetCurrentUser(NameSpace oNS) {
currentUserSMTP = GetRecipientEmail(currentUser);
currentUserName = currentUser.Name;
} catch (System.Exception ex) {
log.Warn("OGCS is unable to interogate CurrentUser from Outlook.");
if (OGCSexception.GetErrorCode(ex) == "0x80004004") { //E_ABORT
log.Warn("Corporate policy or possibly anti-virus is blocking access to GAL.");
} else OGCSexception.Analyse(ex);
log.Warn("OGCS is unable to interogate CurrentUser from Outlook.");
} else OGCSexception.Analyse(OGCSexception.LogAsFail(ex));
profile.OutlookGalBlocked = true;
return oNS;
}
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookOld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ public NameSpace GetCurrentUser(NameSpace oNS) {
delay = maxDelay;
} catch (System.Exception ex2) {
if (delay == maxDelay) {
log.Warn("OGCS is unable to obtain CurrentUser from Outlook.");
if (OGCSexception.GetErrorCode(ex2) == "0x80004004") { //E_ABORT
log.Warn("Corporate policy or possibly anti-virus is blocking access to GAL.");
} else OGCSexception.Analyse(ex2);
log.Warn("OGCS is unable to obtain CurrentUser from Outlook.");
} else OGCSexception.Analyse(OGCSexception.LogAsFail(ex2));
profile.OutlookGalBlocked = true;
return oNS;
}
Expand Down
3 changes: 2 additions & 1 deletion src/OutlookGoogleCalendarSync/SettingsStore/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public static SettingsStore.Calendar InPlay() {
SettingsStore.Calendar aProfile;

if (Program.CalledByProcess("manualSynchronize,Sync_Click,updateGUIsettings,UpdateGUIsettings_Profile,miCatRefresh_Click," +
"GetMyGoogleCalendars_Click,btColourMap_Click,ColourPicker_Enter,OnSelectedIndexChanged,OnCheckedChanged")) {
"GetMyGoogleCalendars_Click,btColourMap_Click,btTestOutlookFilter_Click,ColourPicker_Enter,OnSelectedIndexChanged,OnCheckedChanged")) {
aProfile = Forms.Main.Instance.ActiveCalendarProfile;
log.Fine("Using profile Forms.Main.Instance.ActiveCalendarProfile");

Expand All @@ -467,6 +467,7 @@ public static SettingsStore.Calendar InPlay() {
log.Error("Unknown profile being referenced.");
aProfile = Forms.Main.Instance.ActiveCalendarProfile;
}
if (aProfile == null) log.Warn("The profile in play is NULL!");
return aProfile;
}
}
Expand Down
23 changes: 18 additions & 5 deletions src/OutlookGoogleCalendarSync/SettingsStore/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,24 @@ private static void upgradeToMultiCalendar() {
} finally {
if (xml != null) {
xml.Root.Sort();
try {
xml.Save(Settings.ConfigFile);
} catch (System.Exception ex) {
OGCSexception.Analyse("Could not save upgraded settings file " + Settings.ConfigFile, ex);
throw ex;
while (true) {
try {
xml.Save(Settings.ConfigFile);
break;
} catch (System.IO.IOException ex) {
log.Fail("Another process has locked file " + Settings.ConfigFile);
if (MessageBox.Show("Another program is using the settings file " + Settings.ConfigFile +
"\r\nPlease close any other instance of OGCS that may be using it.",
"Settings Cannot Be Saved", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
{
log.Warn("User cancelled attempt to save new settings file.");
OGCSexception.Analyse("Could not save upgraded settings file " + Settings.ConfigFile, ex);
throw;
}
} catch (System.Exception ex) {
OGCSexception.Analyse("Could not save upgraded settings file " + Settings.ConfigFile, ex);
throw;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/Sync/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void skipCorruptedItem(ref List<AppointmentItem> outlookEntries, Appoint
itemSummary = cai.Subject;
}
}
Forms.Main.Instance.Console.Update("<p>" + itemSummary + "</p><p>There is probem with this item - it will not be synced.</p><p>" + errMsg + "</p>",
Forms.Main.Instance.Console.Update("<p>" + itemSummary + "</p><p>There is problem with this item - it will not be synced.</p><p>" + errMsg + "</p>",
Console.Markup.warning, logit: true);

} finally {
Expand Down

0 comments on commit 6551fa5

Please sign in to comment.