Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dyn 5339 backup settings #13853

Merged
merged 15 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/DynamoCore/Configuration/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class PathManager : IPathManager
private readonly string commonPackages;
private readonly string logDirectory;
private readonly string samplesDirectory;
private readonly string backupDirectory;
private string backupDirectory;
private string defaultBackupDirectory;
private readonly string preferenceFilePath;
private string pythonTemplateFilePath;

Expand Down Expand Up @@ -232,6 +233,11 @@ public string BackupDirectory
get { return backupDirectory; }
}

public string DefaultBackupDirectory
{
get { return defaultBackupDirectory; }
}

public string PreferenceFilePath
{
get { return preferenceFilePath; }
Expand Down Expand Up @@ -405,6 +411,7 @@ internal PathManager(PathManagerParams pathManagerParams)
preferenceFilePath = Path.Combine(userDataDir, PreferenceSettingsFileName);
pythonTemplateFilePath = Path.Combine(userDataDir, PythonTemplateFileName);
backupDirectory = Path.Combine(userDataDirNoVersion, BackupDirectoryName);
defaultBackupDirectory = backupDirectory;

// Common directories.
commonDataDir = GetCommonDataFolder();
Expand Down Expand Up @@ -460,6 +467,16 @@ internal void EnsureDirectoryExistence(List<Exception> exceptions)
exceptions.RemoveAll(x => x == null); // Remove all null entries.
}

internal bool UpdateBackupLocation(string newBackupLocation)
{
bool isValidFolder = PathHelper.CreateFolderIfNotExist(newBackupLocation) == null;
if (!isValidFolder)
return false;

backupDirectory = newBackupLocation;
return true;
}

/// <summary>
/// Returns the backup file path for a workspace
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class PreferenceSettings : NotificationObject, IPreferences, IRenderPreci
private bool isEnablePersistExtensionsEnabled;
private bool isStaticSplashScreenEnabled;
private bool isCreatedFromValidFile = true;
private string backupLocation;

#region Constants
/// <summary>
Expand Down Expand Up @@ -357,6 +358,19 @@ public int MaxNumRecentFiles
/// </summary>
public List<string> RecentFiles { get; set; }

/// <summary>
/// Backup files path
/// </summary>
public string BackupLocation
{
get { return backupLocation; }
set
{
backupLocation = value;
RaisePropertyChanged(nameof(BackupLocation));
}
}

/// <summary>
/// A list of backup file paths.
/// </summary>
Expand Down Expand Up @@ -801,6 +815,7 @@ public PreferenceSettings()
BackupInterval = DefaultBackupInterval;
BackupFilesCount = 1;
BackupFiles = new List<string>();
BackupLocation = string.Empty;

LibraryZoomScale = 100;
PythonScriptZoomScale = 100;
Expand All @@ -821,6 +836,7 @@ public PreferenceSettings()
GroupStyleItemsList = new List<GroupStyleItem>();
ReadNotificationIds = new List<string>();
DynamoPlayerFolderGroups = new List<DynamoPlayerFolderGroup>();
backupLocation = string.Empty;
}

/// <summary>
Expand Down
35 changes: 28 additions & 7 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ protected DynamoModel(IStartConfiguration config)
geometryFactoryPath = config.GeometryFactoryPath;

OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenInitPreferencesSettings, 30));

IPreferences preferences = CreateOrLoadPreferences(config.Preferences);
if (preferences is PreferenceSettings settings)
{
Expand Down Expand Up @@ -796,7 +797,7 @@ protected DynamoModel(IStartConfiguration config)
PreferenceSettings.AddDefaultTrustedLocations();
}

InitializePreferences(PreferenceSettings);
InitializePreferences();

// At this point, pathManager.PackageDirectories only has 1 element which is the directory
// in AppData. If list of PackageFolders is empty, add the folder in AppData to the list since there
Expand Down Expand Up @@ -1668,17 +1669,37 @@ private IPreferences CreateOrLoadPreferences(IPreferences preferences)
return new PreferenceSettings();
}

private static void InitializePreferences(IPreferences preferences)
private void InitializePreferences()
{
ProtoCore.Mirror.MirrorData.PrecisionFormat = DynamoUnits.Display.PrecisionFormat = preferences.NumberFormat;

var settings = preferences as PreferenceSettings;
if (settings != null)
if (PreferenceSettings != null)
{
settings.InitializeNamespacesToExcludeFromLibrary();
ProtoCore.Mirror.MirrorData.PrecisionFormat = DynamoUnits.Display.PrecisionFormat = PreferenceSettings.NumberFormat;
PreferenceSettings.InitializeNamespacesToExcludeFromLibrary();

if (string.IsNullOrEmpty(PreferenceSettings.BackupLocation))
{
PreferenceSettings.BackupLocation = pathManager.DefaultBackupDirectory;
}

UpdateBackupLocation(PreferenceSettings.BackupLocation);
}
}

internal bool UpdateBackupLocation(string selectedBackupLocation)
{
return pathManager.UpdateBackupLocation(selectedBackupLocation);
}

internal bool IsDefaultBackupLocation()
{
return PreferenceSettings.BackupLocation.Equals(pathManager.DefaultBackupDirectory);
}

internal string DefaultBackupLocation()
{
return pathManager.DefaultBackupDirectory;
}

/// <summary>
/// Responds to property update notifications on the preferences,
/// and synchronizes with the Units Manager.
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,8 @@
<Resource Include="UI\Images\down_16_16.png" />
<Resource Include="UI\Images\edit_folder_16px_default.png" />
<Resource Include="UI\Images\edit_folder_16px_hover.png" />
<Resource Include="UI\Images\reset-default.png" />
<Resource Include="UI\Images\reset-hover.png" />
<Resource Include="UI\Images\up_16_16.png" />
<Resource Include="UI\Images\up-hover-16px.png" />
<Resource Include="UI\Images\link-16px.png" />
Expand Down
102 changes: 88 additions & 14 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2371,10 +2371,18 @@ You can try disabling loading packages from built-in package paths, or unload th

Do you wish to uninstall {1}? Restart {2} to complete the uninstall and try downloading {0} again.</value>
</data>
<data name="PreferencesViewVisualSettingsGeoScaling" xml:space="preserve">
<data name="PreferencesViewGeneralSettingsRun" xml:space="preserve">
<value>Run Settings</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewGeneralSettingsGeoScaling" xml:space="preserve">
<value>Default Geometry Scaling</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewGeneralSettingsBackup" xml:space="preserve">
<value>Backup Settings</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewVisualSettingsGroupStyles" xml:space="preserve">
<value>Group Styles</value>
<comment>Expander Header Name</comment>
Expand Down Expand Up @@ -3360,6 +3368,25 @@ You can manage this in Preferences -&gt; Security.</value>
<value>Auto-Backup Interval</value>
<comment>Setting menu | Auto-Backup Interval</comment>
</data>
<data name="PreferencesSettingDefaultBackupLocation" xml:space="preserve">
<value>Default Backup Location</value>
<comment>Default Backup Location</comment>
</data>
<data name="PreferencesSettingUpdateBackupLocationTooltip" xml:space="preserve">
<value>Edit Backup Location</value>
</data>
<data name="PreferencesSettingResetBackupLocationTooltip" xml:space="preserve">
<value>Reset Backup Location</value>
</data>
<data name="PreferencesSettingsBackupLocationDialogTitle" xml:space="preserve">
<value>Select Folder to Backup</value>
</data>
<data name="PreferencesSettingsBackupFailedTitle" xml:space="preserve">
<value>Backup location Failed</value>
</data>
<data name="PreferencesSettingsBackupFailedMessage" xml:space="preserve">
<value>Invalid Backup location</value>
</data>
<data name="PreferencesSettingMaxRecentFiles" xml:space="preserve">
<value>Maximum Number of Recent Files</value>
<comment>Setting menu | Maximum Number of Recent Files</comment>
Expand Down
29 changes: 28 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2590,10 +2590,18 @@ You can try disabling loading packages from built-in package paths, or unload th

Do you wish to uninstall {1}? Restart {2} to complete the uninstall and try downloading {0} again.</value>
</data>
<data name="PreferencesViewVisualSettingsGeoScaling" xml:space="preserve">
<data name="PreferencesViewGeneralSettingsRun" xml:space="preserve">
<value>Run Settings</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewGeneralSettingsGeoScaling" xml:space="preserve">
<value>Default Geometry Scaling</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewGeneralSettingsBackup" xml:space="preserve">
<value>Backup Settings</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewVisualSettingsGroupStyles" xml:space="preserve">
<value>Group Styles</value>
<comment>Expander Header Name</comment>
Expand Down Expand Up @@ -3347,6 +3355,25 @@ You can manage this in Preferences -&gt; Security.</value>
<value>Auto-Backup Interval</value>
<comment>Setting menu | Auto-Backup Interval</comment>
</data>
<data name="PreferencesSettingDefaultBackupLocation" xml:space="preserve">
<value>Default Backup Location</value>
<comment>Default Backup Location</comment>
</data>
<data name="PreferencesSettingUpdateBackupLocationTooltip" xml:space="preserve">
<value>Edit Backup Location</value>
</data>
<data name="PreferencesSettingResetBackupLocationTooltip" xml:space="preserve">
<value>Reset Backup Location</value>
</data>
<data name="PreferencesSettingsBackupLocationDialogTitle" xml:space="preserve">
<value>Select Folder to Backup</value>
</data>
<data name="PreferencesSettingsBackupFailedTitle" xml:space="preserve">
<value>Backup location Failed</value>
</data>
<data name="PreferencesSettingsBackupFailedMessage" xml:space="preserve">
<value>Invalid Backup location</value>
</data>
<data name="PreferencesSettingMaxRecentFiles" xml:space="preserve">
<value>Maximum Number of Recent Files</value>
<comment>Setting menu | Maximum Number of Recent Files</comment>
Expand Down
Binary file added src/DynamoCoreWpf/UI/Images/reset-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/DynamoCoreWpf/UI/Images/reset-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading