public static bool CheckContainsAnyItem(string Path, ItemFilters Filter)
        {
            if (string.IsNullOrWhiteSpace(Path))
            {
                throw new ArgumentException("Argument could not be empty", nameof(Path));
            }

            IntPtr Ptr = FindFirstFileExFromApp(System.IO.Path.Combine(Path, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

            try
            {
                if (Ptr.ToInt64() != -1)
                {
                    do
                    {
                        FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                        if (!Attribute.HasFlag(FileAttributes.System))
                        {
                            if (Attribute.HasFlag(FileAttributes.Directory) && Filter.HasFlag(ItemFilters.Folder))
                            {
                                if (Data.cFileName != "." && Data.cFileName != "..")
                                {
                                    return(true);
                                }
                            }
                            else if (Filter.HasFlag(ItemFilters.File) && !Data.cFileName.EndsWith(".url"))
                            {
                                return(true);
                            }
                        }
                    }while (FindNextFile(Ptr, out Data));

                    return(false);
                }
                else
                {
                    Debug.WriteLine(new Win32Exception(Marshal.GetLastWin32Error()).Message);
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
            finally
            {
                FindClose(Ptr);
            }
        }
        private void StartButton_Click(object sender, EventArgs e)
        {
            // this is where the start button comes to .
            StartButton.Enabled = false;
            SinTreeAutoClassification.SinTreeAutoClassification autoClassification =
                new SinTreeAutoClassification.SinTreeAutoClassification(intensityEstimation, neighbourhoodEstimation, sourceClasses, treeLocations);

            System.IO.FileAttributes attr = System.IO.File.GetAttributes(lasFilePath);
            // dir
            if (attr.HasFlag(System.IO.FileAttributes.Directory))
            {
                string[] files = System.IO.Directory.GetFiles(lasFilePath, "*.las");
                foreach (string lasFile in files)
                {
                    // for each file, run classify
                    autoClassification.Classify(lasFile);
                }
            }
            //file
            else
            {
                if (System.IO.File.Exists(lasFilePath))
                {
                    autoClassification.Classify(lasFilePath);
                }
                else
                {
                    MessageBox.Show(String.Format("{0}{1}File not exists!", lasFilePath, Environment.NewLine), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            autoClassification.Dispose();
            MessageBox.Show("Classification Done!", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information);
            StartButton.Enabled = true;
        }
        /// <summary>
        /// 设置文件可写
        /// </summary>
        public static bool SetFileWritable(string filePath)
        {
            string fullPath = filePath;

            //convert assetPath to absolute path
            if (fullPath.StartsWith("Assets/"))
            {
                fullPath = AssetPathToAbsPath(fullPath);
            }

            try
            {
                System.IO.FileAttributes fa = System.IO.File.GetAttributes(fullPath);
                if (fa.HasFlag(System.IO.FileAttributes.ReadOnly))
                {
                    System.IO.File.SetAttributes(fullPath, System.IO.FileAttributes.Normal);
                }
                return(true);
            }
            catch (System.Exception e)
            {
                Debug.LogErrorFormat("Fail to set file({0}) be writable, for the reason of {1}", filePath, e.Message);
                return(false);
            }
        }
Example #4
0
            public bool SelectFile(string filepath, bool canReturn, bool append = false)
            {
                if (this.multifile == false)
                {
                    append = false;
                }

                foreach (FileBrowserArea fba in this.browserAreas)
                {
                    fba.SelectFile(filepath, append);
                }

                if (string.IsNullOrEmpty(filepath) == false)
                {
                    System.IO.FileAttributes fileSelAttr =
                        System.IO.File.GetAttributes(filepath);

                    if (
                        this.singleClickFolder == true &&
                        fileSelAttr.HasFlag(System.IO.FileAttributes.Directory) == true)
                    {
                        this.ViewDirectory(filepath, NavigationType.SelectBrowser, true);
                    }
                    else if (this.singleClickFile == true && canReturn == true)
                    {
                        this.ReturnFile(filepath);
                    }
                }

                return(true);
            }
Example #5
0
        } // End Function IsSymLink

        private static bool IsSymLink(string path)
        {
            // get the file attributes for file or directory
            System.IO.FileAttributes attr = System.IO.File.GetAttributes(path);

            return(attr.HasFlag(System.IO.FileAttributes.ReparsePoint));
        } // End Function IsSymLink
Example #6
0
 private bool hasAccessToRead(string path)
 {
     System.IO.FileAttributes attr = System.IO.File.GetAttributes(path);
     if (!attr.HasFlag(System.IO.FileAttributes.Hidden))
     {
         return(true);
     }
     return(false);
 }
            char OnValidateInput(string text, int charIndex, char addedChar)
            {
                if (addedChar == '\n' || addedChar == '\r')
                {
                    if (Input.GetKeyDown(KeyCode.Return) == true)
                    {
                        string dir  = string.Empty;
                        string path = string.Empty;

                        try
                        {
                            if (System.IO.Path.IsPathRooted(text) == false)
                            {
                                text = System.IO.Path.Combine(this.browser.CurDirectory, text);
                            }

                            System.IO.FileAttributes attr = System.IO.File.GetAttributes(text);
                            if (attr.HasFlag(System.IO.FileAttributes.Directory) == true)
                            {
                                dir = text;
                            }
                            else
                            {
                                path = text;
                            }
                        }
                        catch (System.Exception)
                        { }

                        bool wipeEdit = false;

                        if (string.IsNullOrEmpty(dir) == false)
                        {
                            if (this.browser.ViewDirectory(dir, FileBrowser.NavigationType.FileInput) == true)
                            {
                                wipeEdit = true;
                            }
                        }
                        else if (string.IsNullOrEmpty(path) == false)
                        {
                            if (this.browser.SelectFile(path, true) == true)
                            {
                                wipeEdit = true;
                            }
                        }

                        if (wipeEdit == true)
                        {
                            this.input.text = string.Empty;
                        }
                    }

                    return((char)0);
                }

                return(addedChar);
            }
Example #8
0
        private bool isDir(string pathtocheck)
        {
            System.IO.FileAttributes attr = System.IO.File.GetAttributes(pathtocheck);
            if (attr.HasFlag(System.IO.FileAttributes.Directory))
            {
                return(true);
            }



            return(false);
        }
 internal static IFileSystemInformation Create(string path, System.IO.FileAttributes attributes, IFileService fileService)
 {
     if (attributes.HasFlag(System.IO.FileAttributes.Directory))
     {
         return(DirectoryInformation.Create(path, attributes, fileService));
     }
     else
     {
         // Should only be using attributes for root directories
         throw new InvalidOperationException();
     }
 }
        public static FileAttributes FromIOFileAttributes(System.IO.FileAttributes attrs)
        {
            FileAttributes outvalue = FileAttributes.Normal;

            if (attrs.HasFlag(System.IO.FileAttributes.ReadOnly))
            {
                outvalue |= FileAttributes.ReadOnly;
            }
            if (attrs.HasFlag(System.IO.FileAttributes.Directory))
            {
                outvalue |= FileAttributes.Directory;
            }
            if (attrs.HasFlag(System.IO.FileAttributes.Archive))
            {
                outvalue |= FileAttributes.Archive;
            }
            if (attrs.HasFlag(System.IO.FileAttributes.Temporary))
            {
                outvalue |= FileAttributes.Temporary;
            }

            return(outvalue);
        }
Example #11
0
        static void playerWindow_OnMediaEnded(MediaFile file)
        {
            string infoPath = file.Path + ".info";

            if (System.IO.File.Exists(infoPath))
            {
                System.IO.File.Delete(infoPath);
            }

            System.IO.FileAttributes attrs = System.IO.File.GetAttributes(file.Path);
            if (attrs.HasFlag(System.IO.FileAttributes.ReadOnly))
            {
                System.IO.File.SetAttributes(file.Path, System.IO.FileAttributes.Normal);
            }
            System.IO.File.Delete(file.Path);
        }
Example #12
0
        } // End Function IsSymLink

        public static bool IsDirectory(string path)
        {
            if (!System.IO.File.Exists(path) && !System.IO.Directory.Exists(path))
            {
                return(false);
            }

            // get the file attributes for file or directory
            System.IO.FileAttributes attr = System.IO.File.GetAttributes(path);

            if (attr.HasFlag(System.IO.FileAttributes.Directory))
            {
                return(true);
            }

            return(false);
        }
Example #13
0
 public void AddPaths(string[] paths)
 {
     foreach (var path in paths)
     {
         System.IO.FileAttributes attributes = System.IO.File.GetAttributes(path);
         if (attributes.HasFlag(System.IO.FileAttributes.Directory))
         {
             var fileNames = System.IO.Directory.EnumerateFiles(path, "*.*", System.IO.SearchOption.AllDirectories)
                             .Where(s => IsSupportedFile(s));
             foreach (var fileName in fileNames)
             {
                 AddFile(fileName);
             }
         }
         else
         {
             AddFile(path);
         }
     }
 }
Example #14
0
        public static void UseOpenFolderOrFileExtensions(
            this Microsoft.AspNetCore.Builder.IApplicationBuilder app
            , string path)
        {
            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Equals(new Microsoft.AspNetCore.Http.PathString(path), System.StringComparison.InvariantCultureIgnoreCase))
                {
                    //System.Diagnostics.Process.Start("explorer.exe", "file:///D:/");

                    System.Uri uri = new System.Uri(@"D:\temp\SQL\COR_Basic_Demo_V4_sts.bak");
                    if (System.Environment.OSVersion.Platform == System.PlatformID.Unix)
                    {
                        uri = new System.Uri(@"/root/Downloads/built-compare.zip");
                    }

                    string fileUri = uri.AbsoluteUri;

                    // turns a Uri back into a local filepath too for anyone that needs this.
                    // string path = new System.Uri("file:///C:/whatever.txt").LocalPath;

                    System.IO.FileAttributes attr = System.IO.File.GetAttributes(uri.LocalPath);

                    if (attr.HasFlag(System.IO.FileAttributes.Directory))
                    {
                        System.Console.WriteLine("Its a directory");
                    }
                    else
                    {
                        System.Console.WriteLine("Its a file");
                    }



                    if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
                    {
                        //  open -a Finder myTextFile.txt.
                        using (System.Diagnostics.Process.Start("open", "-a Finder \"" + fileUri + "\"")) { }
                    }
                    else if (System.Environment.OSVersion.Platform == System.PlatformID.Unix)
                    {
                        // nautilus <path_to_file>
                        // activate window
                        // gnome-open PATH

                        // open zip file in archiver
                        // xdg-open file


                        // open explorer window with file
                        // nautilus filename

                        // https://github.com/mono/dbus-sharp
                        // https://developers.redhat.com/blog/2017/09/18/connecting-net-core-d-bus/
                        // https://unix.stackexchange.com/questions/202214/how-can-i-open-thunar-so-that-it-selects-specific-file

                        //  open -a Finder myTextFile.txt.

                        try
                        {
                            using (System.Diagnostics.Process.Start("nautilus1", "\"" + fileUri + "\"")) { }
                        }
                        catch (System.Exception e)
                        {
                            System.Console.WriteLine(e);
                        }
                    }
                    else
                    {
                        // explorer.exe /select,"C:\Folder\subfolder\file.txt"

                        using (System.Diagnostics.Process.Start("explorer.exe", "/select,\"" + fileUri + "\"")) { }
                    }



                    //if (context.WebSockets.IsWebSocketRequest)
                    //{
                    //    System.Net.WebSockets.WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
                    //    await Echo(context, webSocket);
                    //}
                    //else
                    //{
                    //    context.Response.StatusCode = 400;
                    //}
                }
                else
                {
                    await next();
                }
            });
        } // End Sub UseOpenFolderOrFileExtensions(this Microsoft.AspNetCore.Builder.IApplicationBuilder app)
        public static List <FileSystemStorageItemBase> GetStorageItems(params string[] PathArray)
        {
            if (PathArray.Length == 0 || PathArray.Any((Item) => string.IsNullOrWhiteSpace(Item)))
            {
                throw new ArgumentException("Argument could not be empty", nameof(PathArray));
            }

            try
            {
                List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>(PathArray.Length);

                foreach (string Path in PathArray)
                {
                    IntPtr Ptr = FindFirstFileExFromApp(Path, FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

                    try
                    {
                        if (Ptr.ToInt64() != -1)
                        {
                            FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                            if (!Attribute.HasFlag(FileAttributes.System))
                            {
                                if (Attribute.HasFlag(FileAttributes.Directory))
                                {
                                    if (Data.cFileName != "." && Data.cFileName != "..")
                                    {
                                        FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                        DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                        if (Attribute.HasFlag(FileAttributes.Hidden))
                                        {
                                            Result.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, Path, ModifiedTime.ToLocalTime()));
                                        }
                                        else
                                        {
                                            Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, Path, ModifiedTime.ToLocalTime()));
                                        }
                                    }
                                }
                                else
                                {
                                    FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                    DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                    if (Attribute.HasFlag(FileAttributes.Hidden))
                                    {
                                        Result.Add(new HiddenStorageItem(Data, StorageItemTypes.File, Path, ModifiedTime.ToLocalTime()));
                                    }
                                    else
                                    {
                                        if (!Data.cFileName.EndsWith(".url"))
                                        {
                                            if (Data.cFileName.EndsWith(".lnk"))
                                            {
                                                Result.Add(new HyperlinkStorageItem(Data, Path, ModifiedTime.ToLocalTime()));
                                            }
                                            else
                                            {
                                                Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, Path, ModifiedTime.ToLocalTime()));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Debug.WriteLine(new Win32Exception(Marshal.GetLastWin32Error()).Message);
                        }
                    }
                    finally
                    {
                        FindClose(Ptr);
                    }
                }

                return(Result);
            }
            catch
            {
                return(new List <FileSystemStorageItemBase>());
            }
        }
        public static List <FileSystemStorageItemBase> GetStorageItems(StorageFolder Folder, bool IncludeHiddenItem, ItemFilters Filter)
        {
            if (Folder == null)
            {
                throw new ArgumentNullException(nameof(Folder), "Argument could not be null");
            }

            IntPtr Ptr = FindFirstFileExFromApp(System.IO.Path.Combine(Folder.Path, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

            try
            {
                if (Ptr.ToInt64() != -1)
                {
                    List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>();

                    do
                    {
                        FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                        if (!Attribute.HasFlag(FileAttributes.System) && (IncludeHiddenItem || !Attribute.HasFlag(FileAttributes.Hidden)))
                        {
                            if (Attribute.HasFlag(FileAttributes.Directory) && Filter.HasFlag(ItemFilters.Folder))
                            {
                                if (Data.cFileName != "." && Data.cFileName != "..")
                                {
                                    FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                    DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                    if (Attribute.HasFlag(FileAttributes.Hidden))
                                    {
                                        Result.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, System.IO.Path.Combine(Folder.Path, Data.cFileName), ModifiedTime.ToLocalTime()));
                                    }
                                    else
                                    {
                                        Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, System.IO.Path.Combine(Folder.Path, Data.cFileName), ModifiedTime.ToLocalTime()));
                                    }
                                }
                            }
                            else if (Filter.HasFlag(ItemFilters.File))
                            {
                                FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                if (Attribute.HasFlag(FileAttributes.Hidden))
                                {
                                    Result.Add(new HiddenStorageItem(Data, StorageItemTypes.File, System.IO.Path.Combine(Folder.Path, Data.cFileName), ModifiedTime.ToLocalTime()));
                                }
                                else
                                {
                                    if (!Data.cFileName.EndsWith(".url"))
                                    {
                                        if (Data.cFileName.EndsWith(".lnk"))
                                        {
                                            Result.Add(new HyperlinkStorageItem(Data, System.IO.Path.Combine(Folder.Path, Data.cFileName), ModifiedTime.ToLocalTime()));
                                        }
                                        else
                                        {
                                            Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, System.IO.Path.Combine(Folder.Path, Data.cFileName), ModifiedTime.ToLocalTime()));
                                        }
                                    }
                                }
                            }
                        }
                    }while (FindNextFile(Ptr, out Data));

                    return(Result);
                }
                else
                {
                    Debug.WriteLine(new Win32Exception(Marshal.GetLastWin32Error()).Message);
                    return(new List <FileSystemStorageItemBase>());
                }
            }
            catch
            {
                return(new List <FileSystemStorageItemBase>());
            }
            finally
            {
                FindClose(Ptr);
            }
        }
Example #17
0
 public static SMBLibrary.FileAttributes MapFileAttributes(System.IO.FileAttributes fileAttributes)
 {
     SMBLibrary.FileAttributes result = 0;
     if (fileAttributes.HasFlag(System.IO.FileAttributes.System))
     {
         result |= SMBLibrary.FileAttributes.System;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.Archive))
     {
         result |= SMBLibrary.FileAttributes.Archive;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.Hidden))
     {
         result |= SMBLibrary.FileAttributes.Hidden;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.Compressed))
     {
         result |= SMBLibrary.FileAttributes.Compressed;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.Directory))
     {
         result |= SMBLibrary.FileAttributes.Directory;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.Encrypted))
     {
         result |= SMBLibrary.FileAttributes.Encrypted;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.Normal))
     {
         result |= SMBLibrary.FileAttributes.Normal;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.ReadOnly))
     {
         result |= SMBLibrary.FileAttributes.ReadOnly;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.IntegrityStream))
     {
         result |= SMBLibrary.FileAttributes.IntegrityStream;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.NoScrubData))
     {
         result |= SMBLibrary.FileAttributes.NoScrubData;
     }
     if (fileAttributes.HasFlag(System.IO.FileAttributes.NotContentIndexed))
     {
         result |= SMBLibrary.FileAttributes.NotContentIndexed;
     }
     return(result);
 }