This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Win Explorer Content Menu Integration
- Loading branch information
Allen Byron Penner
committed
Sep 7, 2015
1 parent
aabda47
commit 37369f0
Showing
9 changed files
with
302 additions
and
6,188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
//Author: DaveyM69 | ||
//Date: 22 May 2010 | ||
//Link: http://www.codeproject.com/Tips/61987/Allow-write-modify-access-to-CommonApplicationData | ||
|
||
using System; | ||
using System.IO; | ||
using System.Security.AccessControl; | ||
using System.Security.Principal; | ||
|
||
namespace FileHasher | ||
{ | ||
class CommonApplicationData | ||
{ | ||
|
||
private string applicationFolder; | ||
private string companyFolder; | ||
private static readonly string directory = | ||
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); | ||
|
||
/// <summary> | ||
/// Creates a new instance of this class creating the specified company and application folders | ||
/// if they don't already exist and optionally allows write/modify to all users. | ||
/// </summary> | ||
/// <param name="companyFolder">The name of the company's folder (normally the company name).</param> | ||
/// <param name="applicationFolder">The name of the application's folder (normally the application name).</param> | ||
/// <remarks>If the application folder already exists then permissions if requested are NOT altered.</remarks> | ||
public CommonApplicationData(string companyFolder, string applicationFolder) | ||
: this(companyFolder, applicationFolder, false) | ||
{ } | ||
/// <summary> | ||
/// Creates a new instance of this class creating the specified company and application folders | ||
/// if they don't already exist and optionally allows write/modify to all users. | ||
/// </summary> | ||
/// <param name="companyFolder">The name of the company's folder (normally the company name).</param> | ||
/// <param name="applicationFolder">The name of the application's folder (normally the application name).</param> | ||
/// <param name="allUsers">true to allow write/modify to all users; otherwise, false.</param> | ||
/// <remarks>If the application folder already exists then permissions if requested are NOT altered.</remarks> | ||
public CommonApplicationData(string companyFolder, string applicationFolder, bool allUsers) | ||
{ | ||
this.applicationFolder = applicationFolder; | ||
this.companyFolder = companyFolder; | ||
CreateFolders(allUsers); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the path of the application's data folder. | ||
/// </summary> | ||
public string ApplicationFolderPath | ||
{ | ||
get { return Path.Combine(CompanyFolderPath, applicationFolder); } | ||
} | ||
/// <summary> | ||
/// Gets the path of the company's data folder. | ||
/// </summary> | ||
public string CompanyFolderPath | ||
{ | ||
get { return Path.Combine(directory, companyFolder); } | ||
} | ||
|
||
private void CreateFolders(bool allUsers) | ||
{ | ||
DirectoryInfo directoryInfo; | ||
DirectorySecurity directorySecurity; | ||
AccessRule rule; | ||
SecurityIdentifier securityIdentifier = new SecurityIdentifier | ||
(WellKnownSidType.BuiltinUsersSid, null); | ||
if (!Directory.Exists(CompanyFolderPath)) | ||
{ | ||
directoryInfo = Directory.CreateDirectory(CompanyFolderPath); | ||
bool modified; | ||
directorySecurity = directoryInfo.GetAccessControl(); | ||
rule = new FileSystemAccessRule( | ||
securityIdentifier, | ||
FileSystemRights.Write | | ||
FileSystemRights.ReadAndExecute | | ||
FileSystemRights.Modify, | ||
AccessControlType.Allow); | ||
directorySecurity.ModifyAccessRule(AccessControlModification.Add, rule, out modified); | ||
directoryInfo.SetAccessControl(directorySecurity); | ||
} | ||
if (!Directory.Exists(ApplicationFolderPath)) | ||
{ | ||
directoryInfo = Directory.CreateDirectory(ApplicationFolderPath); | ||
if (allUsers) | ||
{ | ||
bool modified; | ||
directorySecurity = directoryInfo.GetAccessControl(); | ||
rule = new FileSystemAccessRule( | ||
securityIdentifier, | ||
FileSystemRights.Write | | ||
FileSystemRights.ReadAndExecute | | ||
FileSystemRights.Modify, | ||
InheritanceFlags.ContainerInherit | | ||
InheritanceFlags.ObjectInherit, | ||
PropagationFlags.InheritOnly, | ||
AccessControlType.Allow); | ||
directorySecurity.ModifyAccessRule(AccessControlModification.Add, rule, out modified); | ||
directoryInfo.SetAccessControl(directorySecurity); | ||
} | ||
} | ||
} | ||
/// <summary> | ||
/// Returns the path of the application's data folder. | ||
/// </summary> | ||
/// <returns>The path of the application's data folder.</returns> | ||
public override string ToString() | ||
{ | ||
return ApplicationFolderPath; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.