private void UnblockDLLs() { try { var files = Directory.EnumerateFiles(DirectoryHelper.BaseDirectory, "*", SearchOption.AllDirectories); foreach (var file in files) { bool result = FileSystem.AlternateDataStreamExists(file, ZoneName); if (result) { // Clear the read-only attribute, if set: FileAttributes attributes = File.GetAttributes(file); if (FileAttributes.ReadOnly == (FileAttributes.ReadOnly & attributes)) { attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(file, attributes); } //UnblocK: FileSystem.DeleteAlternateDataStream(file, ZoneName); } } } catch (Exception) { //If unblocking fails, there is a big chance that it isn't needed anyway. //So do nothing. } }
protected override void ProcessPath(PscxPathInfo pscxPath) { try { WriteVerbose("Processing " + pscxPath.ProviderPath); bool exists = FileSystem.AlternateDataStreamExists(pscxPath.ProviderPath, Name); WriteObject(exists); } catch (SecurityException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (UnauthorizedAccessException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (PipelineStoppedException) { throw; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.NotSpecified, pscxPath.ProviderPath)); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { try { foreach (string aName in Name) { if (!FileSystem.AlternateDataStreamExists(pscxPath.ProviderPath, aName)) { this.ErrorHandler.WriteAlternateDataStreamDoentExist(aName, pscxPath.ProviderPath); continue; } string filename = System.IO.Path.GetFileName(pscxPath.ProviderPath); if (this.ShouldProcess(filename, "removing alternate data stream " + aName)) { FileSystem.DeleteAlternateDataStream(pscxPath.ProviderPath, aName); } } } catch (SecurityException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (UnauthorizedAccessException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (PipelineStoppedException) { throw; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.NotSpecified, pscxPath.ProviderPath)); } }
static bool ProcessFile_WhatIf(string path) { bool result = FileSystem.AlternateDataStreamExists(path, ZoneName); if (result) { Console.WriteLine("Process {0}", path); } return(result); }
protected override bool CanShowMenu() { #if DEBUG EventLog.WriteEntry("ACDDokan.Net", $"ContextMenu in {FolderPath} create: {string.Join(";", SelectedItemPaths)}", EventLogEntryType.Warning, 0, 0); #endif if (SelectedItemPaths.Any()) { return(SelectedItemPaths.All(path => FileSystem.AlternateDataStreamExists(path, CloudDokanNetItemInfo.StreamName))); } return(FileSystem.AlternateDataStreamExists(FolderPath, CloudDokanNetItemInfo.StreamName)); }
static void Main(string[] args) { try { const string Path = @"E:\123.txt"; const string StreamName = "stream1"; //FileInfo file = new FileInfo(Path); //if (!file.Exists) //if (!file.AlternateDataStreamExists(StreamName)) //{ //} if (!File.Exists(Path)) { throw new FileNotFoundException(null, Path); } if (!FileSystem.AlternateDataStreamExists(Path, StreamName)) { Console.WriteLine("Stream not found; creating it..."); AlternateDataStreamInfo data = FileSystem.GetAlternateDataStream(Path, StreamName); FileStream fsWriter = data.OpenWrite(); fsWriter.WriteByte(65); fsWriter.Close(); } else { AlternateDataStreamInfo data = FileSystem.GetAlternateDataStream(Path, StreamName); FileStream fsWriter = data.OpenWrite(); fsWriter.WriteByte(97); fsWriter.Close(); } AlternateDataStreamInfo data1 = FileSystem.GetAlternateDataStream(Path, StreamName); FileStream fsReader1 = data1.OpenRead(); byte[] buffer = new byte[100]; fsReader1.Read(buffer, 0, Convert.ToInt32(fsReader1.Length)); FileStream fsWriter1 = data1.OpenWrite(); fsWriter1.WriteByte(49); fsWriter1.Close(); } catch (Exception ex) { Console.WriteLine(ex); } Console.ReadKey(); }
private bool CheckBlockedFiles() { if (Utils.IsLinux) { return(true); } if (Environment.OSVersion.Platform != PlatformID.Win32NT) { // do stuff on windows only return(true); } string programlocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); // ReSharper disable once AssignNullToNotNullAttribute string[] dllFiles = Directory.GetFiles(programlocation, "*.dll", SearchOption.AllDirectories); bool result = true; foreach (string dllFile in dllFiles) { if (FileSystem.AlternateDataStreamExists(dllFile, "Zone.Identifier")) { try { FileSystem.DeleteAlternateDataStream(dllFile, "Zone.Identifier"); } catch { // ignored } } } foreach (string dllFile in dllFiles) { if (FileSystem.AlternateDataStreamExists(dllFile, "Zone.Identifier")) { logger.Log(NLog.LogLevel.Error, "Found blocked DLL file: " + dllFile); result = false; } } return(result); }
static bool ProcessFile_Real(string path) { bool result = FileSystem.AlternateDataStreamExists(path, ZoneName); if (result) { // Clear the read-only attribute, if set: FileAttributes attributes = File.GetAttributes(path); if (FileAttributes.ReadOnly == (FileAttributes.ReadOnly & attributes)) { attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(path, attributes); } result = FileSystem.DeleteAlternateDataStream(path, ZoneName); result = FileSystem.AlternateDataStreamExists(path, ZoneName);//Check } return(result); }
private static Guid _GetID(string uri) { const string TID = "lguid"; if (File.Exists(uri) || Directory.Exists(uri)) { if (FileSystem.AlternateDataStreamExists(uri, TID)) { Logger.D("{0} begin reader", uri); AlternateDataStreamInfo adfs = FileSystem.GetAlternateDataStream(uri, TID); FileStream fs = adfs.OpenRead(); StreamReader sr = new StreamReader(fs); string guid = sr.ReadToEnd(); Logger.D("{0} begin close", uri); sr.Close(); fs.Close(); sr.Dispose(); fs.Dispose(); Logger.D("{0} close reader", uri); return(Guid.Parse(guid)); } else { Guid id = Guid.NewGuid(); AlternateDataStreamInfo adfs = FileSystem.GetAlternateDataStream(uri, TID); FileStream fs = adfs.OpenWrite(); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(id.ToString()); sw.Close(); fs.Close(); sw.Dispose(); fs.Dispose(); return(id); } } else { return(Guid.NewGuid()); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { try { if (List) { IList <AlternateDataStreamInfo> streamInfos = FileSystem.ListAlternateDataStreams(pscxPath.ProviderPath); WriteObject(streamInfos, true); } else { foreach (string aName in Name) { if (!FileSystem.AlternateDataStreamExists(pscxPath.ProviderPath, aName)) { this.ErrorHandler.WriteAlternateDataStreamDoentExist(aName, pscxPath.ProviderPath); continue; } AlternateDataStreamInfo streamInfo = FileSystem.GetAlternateDataStream(pscxPath.ProviderPath, aName); WriteObject(streamInfo); } } } catch (SecurityException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (UnauthorizedAccessException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (PipelineStoppedException) { throw; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.NotSpecified, pscxPath.ProviderPath)); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { try { if (FileSystem.AlternateDataStreamExists(pscxPath.ProviderPath, _adsName)) { string filename = System.IO.Path.GetFileName(pscxPath.ProviderPath); if (this.ShouldProcess(filename, "unblocking file")) { FileSystem.DeleteAlternateDataStream(pscxPath.ProviderPath, _adsName); } } else { WriteWarning(String.Format(Properties.Resources.UnblockedAlready_F1, pscxPath.ProviderPath)); } if (this.PassThru) { WriteObject(base.InputObject); } } catch (SecurityException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (UnauthorizedAccessException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (PipelineStoppedException) { throw; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.NotSpecified, pscxPath.ProviderPath)); } }
protected override bool CanShowMenu() { return(SelectedItemPaths.All((path) => FileSystem.AlternateDataStreamExists(path, ACDDokanNetInfoStreamName))); }