コード例 #1
0
        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.
            }
        }
コード例 #2
0
 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));
     }
 }
コード例 #3
0
 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));
     }
 }
コード例 #4
0
    static bool ProcessFile_WhatIf(string path)
    {
        bool result = FileSystem.AlternateDataStreamExists(path, ZoneName);

        if (result)
        {
            Console.WriteLine("Process {0}", path);
        }
        return(result);
    }
コード例 #5
0
        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));
        }
コード例 #6
0
        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();
        }
コード例 #7
0
ファイル: ShokoServer.cs プロジェクト: Pizz001/ShokoServer
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: NtfsFileID.cs プロジェクト: kummerwu/TagExplorer
        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());
            }
        }
コード例 #10
0
 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));
     }
 }
コード例 #11
0
ファイル: UnblockFileCommand.cs プロジェクト: zyonet/Pscx
        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));
            }
        }
コード例 #12
0
ファイル: ContextMenu.cs プロジェクト: wacowXD/ACDDokanNet
 protected override bool CanShowMenu()
 {
     return(SelectedItemPaths.All((path) => FileSystem.AlternateDataStreamExists(path, ACDDokanNetInfoStreamName)));
 }