You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -58,6 +61,86 @@ public ChocolateyConfiguration()
58
61
#endif
59
62
}
60
63
64
+
/// <summary>
65
+
/// Creates a backup of the current version of the configuration class.
66
+
/// </summary>
67
+
/// <exception cref="System.Runtime.Serialization.SerializationException">One or more objects in the class or child classes are not serializable.</exception>
68
+
publicvoidstart_backup()
69
+
{
70
+
// We do this the easy way to ensure that we have a clean copy
71
+
// of the original configuration file.
72
+
_originalConfiguration=this.deep_copy();
73
+
}
74
+
75
+
/// <summary>
76
+
/// Restore the backup that has previously been created to the initial
77
+
/// state, without making the class reference types the same to prevent
78
+
/// the initial configuration class being updated at the same time if a
79
+
/// value changes.
80
+
/// </summary>
81
+
/// <param name="removeBackup">Whether a backup that was previously made should be removed after resetting the configuration.</param>
82
+
/// <exception cref="InvalidOperationException">No backup has been created before trying to reset the current configuration, and removal of the backup was not requested.</exception>
83
+
/// <remarks>
84
+
/// This call may make quite a lot of allocations on the Gen0 heap, as such
85
+
/// it is best to keep the calls to this method at a minimum.
86
+
/// </remarks>
87
+
publicvoidreset_config(boolremoveBackup=false)
88
+
{
89
+
if(_originalConfiguration==null)
90
+
{
91
+
if(removeBackup)
92
+
{
93
+
// If we will also be removing the backup, we do not care if it is already
94
+
// null or not, as that is the intended state when this method returns.
95
+
return;
96
+
}
97
+
98
+
thrownewInvalidOperationException("No backup has been created before trying to reset the current configuration, and removal of the backup was not requested.");
0 commit comments