Ejemplo n.º 1
0
        /// <summary>
        /// Called when [dir].
        /// </summary>
        /// <param name="Input_Directory">The input directory.</param>
        /// <returns>OnDirResponse object.all files or folders and that info</returns>
        public OnDirResponse OnDir(string Input_Directory)
        {
            OnDirResponse JOnDir = new OnDirResponse();

            try {
                string[] Files_In_Target_Directory = Directory.GetFiles(Input_Directory, "*");
                foreach (string file in Files_In_Target_Directory)
                {
                    OnDirResponse.FileOrDir fileOrdir = new OnDirResponse.FileOrDir();
                    fileOrdir.Path = file;
                    fileOrdir.File_Property_Info = GetProperty(JOnDir, file);
                    JOnDir.fileOrdir.Add(fileOrdir);
                }

                string[] Directorys_in_target_Directory = Directory.GetDirectories(Input_Directory, "*");
                foreach (string dir in Directorys_in_target_Directory)
                {
                    OnDirResponse.FileOrDir fileOrdir = new OnDirResponse.FileOrDir();
                    fileOrdir.Path = dir;
                    fileOrdir.File_Property_Info = GetProperty(JOnDir, dir);
                    JOnDir.fileOrdir.Add(fileOrdir);
                }
            }
            catch (Exception ex)
            {
                JOnDir.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message);
            }
            return(JOnDir);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the property.
        /// </summary>
        /// <param name="ResponseMain">The response main.</param>
        /// <param name="File_Or_Directory">The file or directory.</param>
        /// <returns>the property info of fiel or folder</returns>
        private OnDirResponse.FileOrDir.Property GetProperty(OnDirResponse ResponseMain, string File_Or_Directory)
        {
            OnDirResponse.FileOrDir.Property JGetProperty = new OnDirResponse.FileOrDir.Property();
            try {
                FileInfo fi = new FileInfo(File_Or_Directory);
                JGetProperty.Attributes = fi.Attributes;

                if (fi.Attributes.HasFlag(FileAttributes.Directory))//is dir
                {
                    JGetProperty.Type = "Dir";
                }
                else //is file
                {
                    JGetProperty.Type   = "File";
                    JGetProperty.Length = fi.Length;//why Len is here? because just file have len
                }
                JGetProperty.Accesses       = GetAccessControl(ResponseMain, File_Or_Directory);
                JGetProperty.CreationTime   = fi.CreationTime;
                JGetProperty.IsReadOnly     = fi.IsReadOnly;
                JGetProperty.LastAccessTime = fi.LastAccessTime;
                JGetProperty.LastWriteTime  = fi.LastWriteTime;
            }
            catch (Exception ex)
            {
                ResponseMain.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message);
            }
            return(JGetProperty);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Kills the desktop LNK from path.
        /// </summary>
        /// <param name="InstallLocation">The install location.</param>
        /// <returns>if has lnk return true other return false</returns>
        private bool KillDesktopLNKFromPath(string InstallLocation)
        {
            bool HasLNK = false;

            string[] desktopPath = new string[2];
            desktopPath[0] = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
            desktopPath[1] = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            foreach (string desk in desktopPath)
            {
                _m_File_Manager mfm  = new _m_File_Manager();
                OnDirResponse   Dirs = mfm.OnDir(desk);
                foreach (OnDirResponse.FileOrDir FileOrFolder in Dirs.fileOrdir)
                {
                    //if (FileOrFolder.Path.Contains("Resizer 5"))
                    //{

                    //}
                    if (FileOrFolder.Path.EndsWith(".lnk"))
                    {
                        string TempAddress  = _m_File_Manager.GetShortcutTargetFile(FileOrFolder.Path);
                        string TargetAdress = "";
                        if (TempAddress.EndsWith("\\"))
                        {
                            TargetAdress = TempAddress;
                        }
                        else
                        {
                            TargetAdress = GetPathFromFullPath(TempAddress, true);
                        }

                        if (TargetAdress == InstallLocation)
                        {
                            System.IO.File.Delete(FileOrFolder.Path);
                        }
                    }
                }
            }


            return(HasLNK);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the access control.
        /// </summary>
        /// <param name="ResponseMain">The response main.</param>
        /// <param name="File_Or_Directory">The file or directory.</param>
        /// <returns>reeturn acess control list of file or folder</returns>
        private List <OnDirResponse.FileOrDir.Property.AccessControl> GetAccessControl(OnDirResponse ResponseMain, string File_Or_Directory)
        {
            List <OnDirResponse.FileOrDir.Property.AccessControl> JGetAccessControl = new List <OnDirResponse.FileOrDir.Property.AccessControl>();

            try {
                System.Security.AccessControl.FileSecurity file_sec            = System.IO.File.GetAccessControl(File_Or_Directory);
                System.Security.AccessControl.AuthorizationRuleCollection ruls = file_sec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
                foreach (System.Security.AccessControl.FileSystemAccessRule rul in ruls)
                {
                    OnDirResponse.FileOrDir.Property.AccessControl JRul = new OnDirResponse.FileOrDir.Property.AccessControl();
                    JRul.IdentityReference = rul.IdentityReference.Value;
                    JRul.FileSystemRights  = rul.FileSystemRights.ToString();
                    JRul.AccessControlType = rul.AccessControlType.ToString();
                    JRul.IsInherited       = rul.IsInherited ? "Inherited" : "Explicit";
                    JRul.PropagationFlags  = rul.PropagationFlags.ToString();
                    JRul.InheritanceFlags  = rul.InheritanceFlags.ToString();
                    JRul.Owner             = System.IO.File.GetAccessControl(File_Or_Directory).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();//
                    JGetAccessControl.Add(JRul);
                }
            }catch (Exception ex)
            {
                ResponseMain.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message);
            }
            return(JGetAccessControl);
        }