Exemple #1
0
        public static string TimeSpanToTimeAgo(TimeSpan timeSpan)
        {
            if (timeSpan.TotalDays > 365)
            {
                int years = (int)Math.Ceiling((float)timeSpan.Days / 365);
                return(Localizer.F(Resources.TimeAgo_Years, years));
            }

            if (timeSpan.TotalDays > 1.0)
            {
                return(Localizer.F(Resources.TimeAgo_Days, (int)timeSpan.TotalDays));
            }

            if (timeSpan.TotalHours > 1.0)
            {
                return(Localizer.F(Resources.TimeAgo_Hours, (int)timeSpan.TotalHours));
            }

            if (timeSpan.TotalMinutes > 1.0)
            {
                return(Localizer.F(Resources.TimeAgo_Minutes, (int)timeSpan.TotalMinutes));
            }

            return(Resources.TimeAgo_JustNow);
        }
        public static async Task StartWithErrorDialogAsync(this ISyncThingManager syncThingManager, IWindowManager windowManager)
        {
            try
            {
                await syncThingManager.StartAsync();
            }
            catch (Win32Exception e)
            {
                if (e.ErrorCode != -2147467259)
                {
                    throw;
                }

                // Possibly "This program is blocked by group policy. For more information, contact your system administrator" caused
                // by e.g. CryptoLocker?
                windowManager.ShowMessageBox(
                    Localizer.F(Resources.Dialog_SyncthingBlockedByGroupPolicy_Message, e.Message, syncThingManager.ExecutablePath),
                    Resources.Dialog_SyncthingBlockedByGroupPolicy_Title,
                    MessageBoxButton.OK, icon: MessageBoxImage.Error);
            }
            catch (SyncThingDidNotStartCorrectlyException e)
            {
                windowManager.ShowMessageBox(
                    Localizer.F(Resources.Dialog_SyncthingDidNotStart_Message, e.Message),
                    Resources.Dialog_SyncthingDidNotStart_Title,
                    MessageBoxButton.OK, icon: MessageBoxImage.Error);
            }
        }
Exemple #3
0
        private void FolderSynchronizationFinished(object sender, FolderSynchronizationFinishedEventArgs e)
        {
            bool notificationsEnabled;

            if (this.FolderNotificationsEnabled != null && this.FolderNotificationsEnabled.TryGetValue(e.FolderId, out notificationsEnabled) && notificationsEnabled)
            {
                if (e.FileTransfers.Count == 0)
                {
                    if (this.ShowSynchronizedBalloonEvenIfNothingDownloaded &&
                        DateTime.UtcNow - this.syncThingManager.LastConnectivityEventTime > syncedDeadTime &&
                        DateTime.UtcNow - this.syncThingManager.StartedTime > syncedDeadTime)
                    {
                        this.taskbarIcon.HideBalloonTip();
                        this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_FinishedSyncing_Title, String.Format(Resources.TrayIcon_Balloon_FinishedSyncing_Message, e.FolderId), BalloonIcon.Info);
                    }
                }
                else if (e.FileTransfers.Count == 1)
                {
                    var    fileTransfer = e.FileTransfers[0];
                    string msg          = null;
                    if (fileTransfer.ActionType == ItemChangedActionType.Update)
                    {
                        msg = String.Format(Resources.TrayIcon_Balloon_FinishedSyncing_UpdatedSingleFile, e.FolderId, Path.GetFileName(fileTransfer.Path));
                    }
                    else if (fileTransfer.ActionType == ItemChangedActionType.Delete)
                    {
                        msg = String.Format(Resources.TrayIcon_Balloon_FinishedSyncing_DeletedSingleFile, e.FolderId, Path.GetFileName(fileTransfer.Path));
                    }

                    if (msg != null)
                    {
                        this.taskbarIcon.HideBalloonTip();
                        this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_FinishedSyncing_Title, msg, BalloonIcon.Info);
                    }
                }
                else
                {
                    var updatedCount = e.FileTransfers.Where(x => x.ActionType == ItemChangedActionType.Update).Count();
                    var deletedCount = e.FileTransfers.Where(x => x.ActionType == ItemChangedActionType.Delete).Count();

                    var messageParts = new List <string>();

                    if (updatedCount > 0)
                    {
                        messageParts.Add(Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_UpdatedFile, updatedCount));
                    }

                    if (deletedCount > 0)
                    {
                        messageParts.Add(Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_DeletedFile, deletedCount));
                    }

                    var text = Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_Multiple, e.FolderId, messageParts);

                    this.taskbarIcon.HideBalloonTip();
                    this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_FinishedSyncing_Title, text, BalloonIcon.Info);
                }
            }
        }
            public IndividualFlagsValidator()
            {
                this.RuleFor(x => x).Custom((str, ctx) =>
                {
                    KeyValueStringParser.TryParse(str, out var result, mustHaveValue: false);

                    if (!result.All(flag => flag.Key.StartsWith("-")))
                    {
                        ctx.AddFailure(Resources.SettingsView_Validation_SyncthingCommandLineFlagsMustBeginWithHyphen);
                    }

                    var firstFailure = result.Select(flag => flag.Key).FirstOrDefault(key => forbiddenArgs.Contains(key));
                    if (firstFailure != null)
                    {
                        ctx.AddFailure(Localizer.F(Resources.SettingsView_Validation_SyncthingCommandLineFlagIsNotAllowed, firstFailure));
                    }
                });
            }
 private bool ResolveConflict(ConflictSet conflictSet, string filePath)
 {
     // This can happen e.g. if the file chosen no longer exists
     try
     {
         this.conflictFileManager.ResolveConflict(conflictSet, filePath, this.DeleteToRecycleBin);
         return(true);
     }
     catch (IOException e)
     {
         this.windowManager.ShowMessageBox(
             Localizer.F(Resources.ConflictResolutionView_Dialog_Failed_Message, e.Message),
             Resources.ConflictResolutionView_Dialog_Failed_Title,
             MessageBoxButton.OK,
             MessageBoxImage.Error
             );
         return(false);
     }
 }
            public IndividualFlagsValidator()
            {
                Custom(str =>
                {
                    IEnumerable <KeyValuePair <string, string> > result;
                    KeyValueStringParser.TryParse(str, out result, mustHaveValue: false);

                    if (!result.All(flag => flag.Key.StartsWith("-")))
                    {
                        return(new ValidationFailure(null, Resources.SettingsView_Validation_SyncthingCommandLineFlagsMustBeginWithHyphen));
                    }

                    var firstFailure = result.Select(flag => flag.Key).FirstOrDefault(key => forbiddenArgs.Contains(key));
                    if (firstFailure != null)
                    {
                        return(new ValidationFailure(null, Localizer.F(Resources.SettingsView_Validation_SyncthingCommandLineFlagIsNotAllowed, firstFailure)));
                    }
                    return(null);
                });
            }
 private bool ResolveConflict(ConflictSet conflictSet, string filePath)
 {
     // This can happen e.g. if the file chosen no longer exists
     try
     {
         this.conflictFileManager.ResolveConflict(conflictSet, filePath, this.DeleteToRecycleBin);
         return(true);
     }
     catch (Exception e)
     {
         // So far I've seen IOExeption (no longer exists) and UnauthorizedAccessException
         // Just in case there are any others, be pokemon
         this.windowManager.ShowMessageBox(
             Localizer.F(Resources.ConflictResolutionView_Dialog_Failed_Message, e.Message),
             Resources.ConflictResolutionView_Dialog_Failed_Title,
             MessageBoxButton.OK,
             MessageBoxImage.Error
             );
         return(false);
     }
 }
        private void FolderSynchronizationFinished(object sender, FolderSynchronizationFinishedEventArgs e)
        {
            // If it only contains failed transfers we've seen before, then we don't care.
            // Otherwise we'll keep bugging the user (every minute) for a failing transfer.
            // However, with this behaviour, we'll still remind them about the failure whenever something succeeds (or a new failure is added)
            if (e.FileTransfers.All(x => x.Error != null && !x.IsNewError))
            {
                return;
            }

            bool notificationsEnabled;

            if (this.FolderNotificationsEnabled != null && this.FolderNotificationsEnabled.TryGetValue(e.FolderId, out notificationsEnabled) && notificationsEnabled)
            {
                if (e.FileTransfers.Count == 0)
                {
                    if (this.ShowSynchronizedBalloonEvenIfNothingDownloaded &&
                        DateTime.UtcNow - this.syncthingManager.LastConnectivityEventTime > syncedDeadTime &&
                        DateTime.UtcNow - this.syncthingManager.StartedTime > syncedDeadTime)
                    {
                        this.taskbarIcon.HideBalloonTip();
                        this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_FinishedSyncing_Title, String.Format(Resources.TrayIcon_Balloon_FinishedSyncing_Message, e.FolderId), BalloonIcon.Info);
                    }
                }
                else if (e.FileTransfers.Count == 1)
                {
                    var    fileTransfer = e.FileTransfers[0];
                    string msg          = null;
                    if (fileTransfer.Error == null)
                    {
                        if (fileTransfer.ActionType == ItemChangedActionType.Update)
                        {
                            msg = Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_UpdatedSingleFile, e.FolderId, Path.GetFileName(fileTransfer.Path));
                        }
                        else if (fileTransfer.ActionType == ItemChangedActionType.Delete)
                        {
                            msg = Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_DeletedSingleFile, e.FolderId, Path.GetFileName(fileTransfer.Path));
                        }
                    }
                    else
                    {
                        if (fileTransfer.ActionType == ItemChangedActionType.Update)
                        {
                            msg = Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_FailedToUpdateSingleFile, e.FolderId, Path.GetFileName(fileTransfer.Path), fileTransfer.Error);
                        }
                        else if (fileTransfer.ActionType == ItemChangedActionType.Delete)
                        {
                            msg = Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_FailedToDeleteSingleFile, e.FolderId, Path.GetFileName(fileTransfer.Path), fileTransfer.Error);
                        }
                    }

                    if (msg != null)
                    {
                        this.taskbarIcon.HideBalloonTip();
                        this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_FinishedSyncing_Title, msg, BalloonIcon.Info);
                    }
                }
                else
                {
                    var updates = e.FileTransfers.Where(x => x.ActionType == ItemChangedActionType.Update).ToArray();
                    var deletes = e.FileTransfers.Where(x => x.ActionType == ItemChangedActionType.Delete).ToArray();

                    var messageParts = new List <string>();

                    if (updates.Length > 0)
                    {
                        var failureCount = updates.Count(x => x.Error != null);
                        if (failureCount > 0)
                        {
                            messageParts.Add(Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_UpdatedFileWithFailures, updates.Length, failureCount));
                        }
                        else
                        {
                            messageParts.Add(Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_UpdatedFile, updates.Length));
                        }
                    }


                    if (deletes.Length > 0)
                    {
                        var failureCount = deletes.Count(x => x.Error != null);
                        if (failureCount > 0)
                        {
                            messageParts.Add(Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_DeletedFileWithFailures, deletes.Length, failureCount));
                        }
                        else
                        {
                            messageParts.Add(Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_DeletedFile, deletes.Length));
                        }
                    }

                    var text = Localizer.F(Resources.TrayIcon_Balloon_FinishedSyncing_Multiple, e.FolderId, messageParts);

                    this.taskbarIcon.HideBalloonTip();
                    this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_FinishedSyncing_Title, text, BalloonIcon.Info);
                }
            }
        }
 private void FolderRejected(object sender, FolderRejectedEventArgs e)
 {
     if (this.ShowDeviceOrFolderRejectedBalloons)
     {
         this.taskbarIcon.HideBalloonTip();
         this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_FolderRejected_Title, Localizer.F(Resources.TrayIcon_Balloon_FolderRejected_Message, e.Device.Name, e.FolderId), BalloonIcon.Info);
     }
 }
 private void DeviceDisconnected(object sender, DeviceDisconnectedEventArgs e)
 {
     if (this.ShowDeviceConnectivityBalloons &&
         DateTime.UtcNow - this.syncthingManager.StartedTime > syncedDeadTime)
     {
         this.taskbarIcon.HideBalloonTip();
         this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_DeviceDisconnected_Title, Localizer.F(Resources.TrayIcon_Balloon_DeviceDisconnected_Message, e.Device.Name), BalloonIcon.Info);
     }
 }
Exemple #11
0
 private void DebouncedDeviceConnected(object sender, DeviceConnectedEventArgs e)
 {
     this.taskbarIcon.HideBalloonTip();
     this.taskbarIcon.ShowBalloonTip(Resources.TrayIcon_Balloon_DeviceConnected_Title, Localizer.F(Resources.TrayIcon_Balloon_DeviceConnected_Message, e.Device.Name), BalloonIcon.Info);
 }