public AttributesMenu(string[] args) { if (args != null) { Thread thread = new Thread(WaitingForFileTimes) { IsBackground = true }; thread.Start(); InitializeComponent(); BringToFront(); Activate(); Focus(); FormClosing += AttributesMenu_FormClosing; // Get : Set Attributes foreach (string arg in args) { try { AttributesInfo.GetFileAttributes(arg); } catch (Exception ex) { StartProcess.StartInfo(AppDomain.CurrentDomain.BaseDirectory + "xMenuTools.exe", "\"" + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException() + Environment.NewLine + ex.TargetSite + "\"" + " -catchhandler"); } ThePaths = args; FilePath = arg; DirectoryInfo DirectoryPath = new DirectoryInfo(FilePath); if (DirectoryPath.Parent == null) { FolderPathName = FilePath; } else { FolderPathName = Path.GetFileName(FilePath); } if (File.Exists(arg) && args.Length < 2) { Text = Resources.labelFileName + FolderPathName; } else if (Directory.Exists(arg) && args.Length < 2) { Text = Resources.labelFolderName + FolderPathName; } else { Text = Resources.MultipleFiles; } SetFileAttributes(); } } else { throw new ArgumentNullException(Resources.ErrorTitle); } }
private void ReadOnlyCheckBox_CheckedChanged(object sender, EventArgs e) { foreach (string arg in ThePaths) { try { FileAttributes attributes = File.GetAttributes(arg); if (ReadOnlyCheckBox.Checked == true) { File.SetAttributes(arg, File.GetAttributes(arg) | FileAttributes.ReadOnly); } else { attributes = AttributesInfo.RemoveAttribute(attributes, FileAttributes.ReadOnly); File.SetAttributes(arg, attributes); } } catch (UnauthorizedAccessException) { ReadOnlyCheckBox.Enabled = false; ReadOnlyCheckBox.Text = Resources.SetReadOnlyUnauthorized; } } }