Provides support for the IResourceUser interface as well as providing access to an application-specific subfolder of the system-defined ApplicationData folder path.
For a list of all members of this type, see ResourceMgr Members.
System.Object
ResourceMgr
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
The ResourceMgr class, in conjunction with the IResourceUser interface, provides a powerful mechanism for your application to purge and refresh external file resources embedded in your binaries. Often an application includes files other than just the executable and associated DLLs, perhaps an XML file, text files, languages files, etc. One approach to file management is to package these files with an installer for your application. A second approach, taken here, is to include these files as resources packaged within your executable or DLL, which are then unpackaged not by an installer but at runtime by the application itself and only if needed. Often you may allow or even encourage users to edit such externalized files; that is a common reason for making them external. But as an application designer you must decide wisely when—or if—to regenerate these files. You do not, for example, want to recreate them every time the application starts; otherwise your users would lose any changes they might have manually made. A good compromise that I use is this: when a new version of an application runs for the first time it overwrites the previous file if it exists and only if it is not protected with the read-only attribute. This allows each user to decide between keeping user changes from version to version and getting a fresh (possibly updated) version with a new release. Furthermore, I only externalize a file just when it is about to be used; if it is not needed in a given run of the application (and it does not yet exist) I do not create it yet. This class provides the ResetAllResources and InstantiateResource methods as your main application API, and ResetResources for instrumenting any child controls and forms as needed.
Since CleanCode 0.9.26.
if (Properties.Settings.Default.NewVersion)
{
// migrate settings from previous version, if any
Properties.Settings.Default.Upgrade();
// deactivate the NewVersion flag for subsequent invocations
Properties.Settings.Default.NewVersion = false;
// Include this here or during your shutdown code to save the above changes
Properties.Settings.Default.Save();
// Reset all file resources associated with this WinForm application
Collection<string> l = ResourceMgr.ResetAllResources(this);
}
To later externalize a particular file from a resource, use code like this:
string fileName = ResourceMgr.InstantiateResource(
"QueryLibrary.xml", Properties.Resources.QueryLibrary);
Namespace: CleanCode.IO
Assembly: CleanCode (in CleanCode.dll)
ResourceMgr Members | CleanCode.IO Namespace