Ejemplo n.º 1
0
        public static bool ReadOnly(string file)
        {
            if (file.Equals(""))
            {
                return(false);
            }

            string location = RuntimeVariables.GetInstance().GetWholeLocation() + "//" + file;

            if (FileValidator.IsDirectory(file))
            {
                if (!Directory.Exists(location))
                {
                    return(false);
                }

                DirectoryInfo info = new DirectoryInfo(location);
                return((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly);
            }
            else
            {
                if (!File.Exists(location))
                {
                    return(false);
                }

                FileInfo info = new FileInfo(location);
                return(info.IsReadOnly);
            }
        }
Ejemplo n.º 2
0
        public static DateTime GetCreation(string file)
        {
            if (file.Equals(""))
            {
                return(DateTime.MinValue);
            }

            string address = RuntimeVariables.GetInstance().GetWholeLocation() + "//" + file;

            try
            {
                if (FileValidator.IsDirectory(file))
                {
                    return(System.IO.Directory.GetCreationTime(@address));
                }
                else
                {
                    return(System.IO.File.GetCreationTime(@address));
                }
            }
            catch (Exception)
            {
                return(DateTime.MinValue);
            }
        }
Ejemplo n.º 3
0
        public static decimal GetSize(string file)
        {
            if (file.Equals(""))
            {
                return(0);
            }

            string location = RuntimeVariables.GetInstance().GetWholeLocation() + "//" + file;

            try
            {
                if (FileValidator.IsDirectory(location))
                {
                    return((decimal)(DirSize(new DirectoryInfo(@location))));
                }
                else
                {
                    return((decimal)(new System.IO.FileInfo(location).Length));
                }
            }
            catch (Exception)
            {
                return(0);
            }
        }
Ejemplo n.º 4
0
        public static bool Hidden(string file)
        {
            if (file.Equals(""))
            {
                return(false);
            }

            string location = RuntimeVariables.GetInstance().GetWholeLocation() + "//" + file;

            if (FileValidator.IsDirectory(file))
            {
                if (!Directory.Exists(location))
                {
                    return(false);
                }

                DirectoryInfo info = new DirectoryInfo(location);
                return((info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden);
            }
            else
            {
                if (!File.Exists(location))
                {
                    return(false);
                }

                return(File.GetAttributes(location).HasFlag(FileAttributes.Hidden));
            }
        }
Ejemplo n.º 5
0
        protected override void FileAction(string fileName, string rawLocation)
        {
            string           location = rawLocation + "\\" + fileName;
            StringCollection paths    = Clipboard.GetFileDropList();

            if (paths.Contains(location))
            {
                string s = FileValidator.IsDirectory(fileName) ? "Directory " : "File ";
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + s + fileName + " is already copied.");
            }

            try
            {
                paths.Add(location);
                RuntimeVariables.GetInstance().Success();
                Logger.GetInstance().LogCommand("Copy " + fileName);
            }
            catch (Exception)
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! Something went wrong during copying " + fileName + ".");
            }

            Clipboard.SetFileDropList(paths);
        }
Ejemplo n.º 6
0
        protected override void FileAction(string fileName, string rawLocation)
        {
            string           location = rawLocation + "\\" + fileName;
            StringCollection paths    = Clipboard.GetFileDropList();

            if (paths.Contains(location))
            {
                string s = FileValidator.IsDirectory(fileName) ? "Directory " : "File ";
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + s + fileName + " is already cut.");
            }

            try
            {
                paths.Add(location);
                DataObject data = new DataObject();
                data.SetFileDropList(paths);
                data.SetData("Preferred DropEffect", DragDropEffects.Move);
                Clipboard.SetDataObject(data, true);

                RuntimeVariables.GetInstance().Success();
                Logger.GetInstance().LogCommand("Cut " + fileName);
            }
            catch (Exception)
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! Something went wrong during cutting " + fileName + ".");
            }
        }
Ejemplo n.º 7
0
        protected override void FileAction(string fileName, string rawLocation)
        {
            string directoryName = destination.ToString();

            if (!FileValidator.IsNameCorrect(directoryName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + directoryName + " contains not allowed characters.");
            }

            string newFileName = newName.ToString();

            if (!FileValidator.IsNameCorrect(newFileName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + newFileName + " contains not allowed characters.");
            }
            if (FileValidator.IsDirectory(newFileName))
            {
                string extension = FileInnerVariable.GetExtension(fileName);
                newFileName += "." + extension;
            }

            string oldLocation = rawLocation + "//" + fileName;
            string newLocation = rawLocation + "//" + directoryName + "//" + newFileName;


            if (!Directory.Exists(rawLocation + "//" + directoryName))
            {
                Directory.CreateDirectory(rawLocation + "//" + directoryName);
            }


            try
            {
                if (forced && File.Exists(newLocation))
                {
                    File.Delete(@newLocation);
                }
                File.Move(@oldLocation, @newLocation);

                RuntimeVariables.GetInstance().Success();
                Logger.GetInstance().LogCommand("Move " + fileName + " to " + directoryName + " as " + newFileName);
            }
            catch (Exception ex)
            {
                RuntimeVariables.GetInstance().Failure();

                if (ex is IOException || ex is UnauthorizedAccessException)
                {
                    throw new CommandException("Action ignored! Access denied during moving " + fileName + " to " + directoryName + " as " + newFileName + ".");
                }
                else
                {
                    throw new CommandException("Action ignored! Something went wrong during moving " + fileName + " to " + directoryName + " as " + newFileName + ".");
                }
            }
        }
Ejemplo n.º 8
0
        public static bool Empty(string file)
        {
            // need to thing about thie method

            if (file.Equals(""))
            {
                return(true);
            }

            string location = RuntimeVariables.GetInstance().GetWholeLocation() + "//" + file;

            if (FileValidator.IsDirectory(file))
            {
                if (Directory.Exists(@location))
                {
                    try
                    {
                        return(Directory.EnumerateFileSystemEntries(location).Any() ? false : true);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (File.Exists(@location))
                {
                    try
                    {
                        if (new FileInfo(location).Length == 0)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
        }
Ejemplo n.º 9
0
        protected override void FileAction(string oldFileName, string rawLocation)
        {
            string newFileName = destination.ToString();

            if (!FileValidator.IsNameCorrect(newFileName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + newFileName + " contains not allowed characters.");
            }

            if (FileValidator.IsDirectory(newFileName))
            {
                string extension = FileInnerVariable.GetExtension(oldFileName);
                newFileName += "." + extension;
            }

            if (oldFileName.Equals(newFileName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! Old name and new name for " + newFileName + " are the same and renaming is unnecessary.");
            }


            string slocation = rawLocation + "//" + oldFileName;
            string nlocation = rawLocation + "//" + newFileName;

            try
            {
                if (forced && File.Exists(nlocation))
                {
                    File.Delete(@nlocation);
                }
                File.Move(@slocation, @nlocation);
                RuntimeVariables.GetInstance().Success();
                Logger.GetInstance().LogCommand("Rename " + oldFileName + " to " + newFileName);
            }
            catch (Exception ex)
            {
                RuntimeVariables.GetInstance().Failure();

                if (ex is IOException || ex is UnauthorizedAccessException)
                {
                    throw new CommandException("Action ignored! Access denied during renaming " + oldFileName + " to " + newFileName + ".");
                }
                else
                {
                    throw new CommandException("Action ignored! Something went wrong during renaming " + oldFileName + " to " + newFileName + ".");
                }
            }
        }
Ejemplo n.º 10
0
        public override void Action(string element)
        {
            if (FileValidator.IsNameCorrect(element))
            {
                string rawLocation = RuntimeVariables.GetInstance().GetWholeLocation();
                string location    = rawLocation + "//" + element;

                if (FileValidator.IsDirectory(element))
                {
                    if (Directory.Exists(location))
                    {
                        if (forced)
                        {
                            Directory.Delete(@location, true);
                        }
                        else
                        {
                            RuntimeVariables.GetInstance().Failure();
                            throw new CommandException("Action ignored! Directory " + element + " already exists and thus cannot be created.");
                        }
                    }
                    DirectoryAction(element, location);
                }
                else
                {
                    if (File.Exists(location))
                    {
                        if (forced)
                        {
                            File.Delete(@location);
                        }
                        else
                        {
                            RuntimeVariables.GetInstance().Failure();
                            throw new CommandException("Action ignored! File " + element + " already exists and thus cannot be created.");
                        }
                    }
                    FileAction(element, location);
                }
            }
            else
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + element + " contains not allowed characters.");
            }
        }
Ejemplo n.º 11
0
        public static bool Exist(string file)
        {
            if (file.Equals(""))
            {
                return(false);
            }

            string location = RuntimeVariables.GetInstance().GetWholeLocation() + "//" + file;

            if (FileValidator.IsDirectory(file))
            {
                return(Directory.Exists(@location));
            }
            else
            {
                return(File.Exists(@location));
            }
        }
Ejemplo n.º 12
0
        public virtual void Action(string element)
        {
            if (element.Trim().Equals(""))
            {
                throw new CommandException("Action ignored! Impossible to perform action on empty element.");
            }

            if (FileValidator.IsNameCorrect(element))
            {
                string rawLocation = RuntimeVariables.GetInstance().GetWholeLocation();
                string location    = rawLocation + "//" + element;

                if (FileValidator.IsDirectory(element))
                {
                    if (!Directory.Exists(@location))
                    {
                        RuntimeVariables.GetInstance().Failure();
                        throw new CommandException("Action ignored! Directory " + element + " not found.");
                    }
                    else
                    {
                        DirectoryAction(element, rawLocation);
                    }
                }
                else
                {
                    if (!File.Exists(@location))
                    {
                        RuntimeVariables.GetInstance().Failure();
                        throw new CommandException("Action ignored! File " + element + " not found.");
                    }
                    else
                    {
                        FileAction(element, rawLocation);
                    }
                }
            }
            else
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + element + " contains not allowed characters.");
            }
        }
Ejemplo n.º 13
0
        public override bool ToBool()
        {
            string file = arg0.ToString();

            return(FileValidator.IsDirectory(file));
        }
Ejemplo n.º 14
0
        public static List <string> OrderBySingleVariable(List <string> source, OrderByStruct order)
        {
            switch (order.GetVariable())
            {
            case OrderByVariable.Empty:
                source = source.OrderBy(s => FileInnerVariable.Empty(s)).ToList();
                break;

            case OrderByVariable.Exist:
                source = source.OrderBy(s => FileInnerVariable.Exist(s)).ToList();
                break;

            case OrderByVariable.Extension:
                source = source.OrderBy(s => FileInnerVariable.GetExtension(s)).ToList();
                break;

            case OrderByVariable.Fullname:
                source = source.OrderBy(s => FileInnerVariable.GetFullname(s)).ToList();
                break;

            case OrderByVariable.Name:
                source = source.OrderBy(s => FileInnerVariable.GetName(s)).ToList();
                break;

            case OrderByVariable.Size:
                source = source.OrderBy(s => FileInnerVariable.GetSize(s)).ToList();
                break;

            case OrderByVariable.IsCorrect:
                source = source.OrderBy(s => FileValidator.IsNameCorrect(s)).ToList();
                break;

            case OrderByVariable.IsDirectory:
                source = source.OrderBy(s => FileValidator.IsDirectory(s)).ToList();
                break;

            case OrderByVariable.IsFile:
                source = source.OrderBy(s => !FileValidator.IsDirectory(s)).ToList();
                break;

            case OrderByVariable.Access:
            {
                if (order is OrderByStructTime)
                {
                    source = source.OrderBy(s => DateExtractor.GetVariable(FileInnerVariable.GetAccess(s),
                                                                           (order as OrderByStructTime).GetTimeVariable())).ToList();
                }
                else if (order is OrderByStructDate)
                {
                    source = source.OrderBy(s => DateExtractor.DateToInt(FileInnerVariable.GetAccess(s))).ToList();
                }
                else if (order is OrderByStructClock)
                {
                    source = source.OrderBy(s => DateExtractor.ClockToInt(FileInnerVariable.GetAccess(s))).ToList();
                }
                else
                {
                    source = source.OrderBy(s => FileInnerVariable.GetAccess(s)).ToList();
                }
                break;
            }

            case OrderByVariable.Creation:
            {
                if (order is OrderByStructTime)
                {
                    source = source.OrderBy(s => DateExtractor.GetVariable(FileInnerVariable.GetCreation(s),
                                                                           (order as OrderByStructTime).GetTimeVariable())).ToList();
                }
                else if (order is OrderByStructDate)
                {
                    source = source.OrderBy(s => DateExtractor.DateToInt(FileInnerVariable.GetCreation(s))).ToList();
                }
                else if (order is OrderByStructClock)
                {
                    source = source.OrderBy(s => DateExtractor.ClockToInt(FileInnerVariable.GetCreation(s))).ToList();
                }
                else
                {
                    source = source.OrderBy(s => FileInnerVariable.GetCreation(s)).ToList();
                }
                break;
            }

            case OrderByVariable.Modification:
            {
                if (order is OrderByStructTime)
                {
                    source = source.OrderBy(s => DateExtractor.GetVariable(FileInnerVariable.GetModification(s),
                                                                           (order as OrderByStructTime).GetTimeVariable())).ToList();
                }
                else if (order is OrderByStructDate)
                {
                    source = source.OrderBy(s => DateExtractor.DateToInt(FileInnerVariable.GetModification(s))).ToList();
                }
                else if (order is OrderByStructClock)
                {
                    source = source.OrderBy(s => DateExtractor.ClockToInt(FileInnerVariable.GetModification(s))).ToList();
                }
                else
                {
                    source = source.OrderBy(s => FileInnerVariable.GetModification(s)).ToList();
                }
                break;
            }
            }

            if (order.GetOrderType().Equals(OrderByType.DESC))
            {
                source.Reverse();
            }

            return(source);
        }
Ejemplo n.º 15
0
        public override bool ToBool()
        {
            string file = RuntimeVariables.GetInstance().GetValueString("this");

            return(FileValidator.IsDirectory(file));
        }
Ejemplo n.º 16
0
        protected override void DirectoryAction(string movingDirectoryName, string rawLocation)
        {
            string directoryName = destination.ToString();

            if (directoryName.Equals(movingDirectoryName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! Directory " + directoryName + " cannot be moved to itself.");
            }

            if (!FileValidator.IsNameCorrect(directoryName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + directoryName + " contains not allowed characters.");
            }

            string newMovingDirectoryName = newName.ToString();

            if (!FileValidator.IsNameCorrect(newMovingDirectoryName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + newMovingDirectoryName + " contains not allowed characters.");
            }
            if (!FileValidator.IsDirectory(newMovingDirectoryName))
            {
                RuntimeVariables.GetInstance().Failure();
                throw new CommandException("Action ignored! " + newMovingDirectoryName + " is not allowed name for directory.");
            }


            string oldLocation = rawLocation + "//" + movingDirectoryName;
            string newLocation = rawLocation + "//" + directoryName + "//" + newMovingDirectoryName;


            if (!Directory.Exists(rawLocation + "//" + directoryName))
            {
                Directory.CreateDirectory(rawLocation + "//" + directoryName);
            }


            try
            {
                if (forced && Directory.Exists(newLocation))
                {
                    Directory.Delete(@newLocation, true);
                }
                Directory.Move(@oldLocation, @newLocation);
                RuntimeVariables.GetInstance().Success();
                Logger.GetInstance().LogCommand("Move " + movingDirectoryName + " to " + directoryName + " as " + newMovingDirectoryName);
            }
            catch (Exception ex)
            {
                RuntimeVariables.GetInstance().Failure();

                if (ex is IOException || ex is UnauthorizedAccessException)
                {
                    throw new CommandException("Action ignored! Access denied during moving " + movingDirectoryName + " to " + directoryName + " as " + newMovingDirectoryName + ".");
                }
                else
                {
                    throw new CommandException("Action ignored! Something went wrong during moving " + movingDirectoryName + " to " + directoryName + " as " + newMovingDirectoryName + ".");
                }
            }
        }
Ejemplo n.º 17
0
        public static bool Equals(string s1, string s2, OrderByStruct order)
        {
            switch (order.GetVariable())
            {
            case OrderByVariable.Empty:
                return(FileInnerVariable.Empty(s1).Equals(FileInnerVariable.Empty(s2)));

            case OrderByVariable.Exist:
                return(FileInnerVariable.Exist(s1).Equals(FileInnerVariable.Exist(s2)));

            case OrderByVariable.Extension:
                return(FileInnerVariable.GetExtension(s1).Equals(FileInnerVariable.GetExtension(s2)));

            case OrderByVariable.Fullname:
                return(FileInnerVariable.GetFullname(s1).Equals(FileInnerVariable.GetFullname(s2)));

            case OrderByVariable.Name:
                return(FileInnerVariable.GetName(s1).Equals(FileInnerVariable.GetName(s2)));

            case OrderByVariable.Size:
                return(FileInnerVariable.GetSize(s1).Equals(FileInnerVariable.GetSize(s2)));

            case OrderByVariable.IsCorrect:
                return(FileValidator.IsNameCorrect(s1).Equals(FileValidator.IsNameCorrect(s2)));

            case OrderByVariable.IsDirectory:
                return(FileValidator.IsDirectory(s1).Equals(FileValidator.IsDirectory(s2)));

            case OrderByVariable.IsFile:
                return(FileValidator.IsDirectory(s1).Equals(FileValidator.IsDirectory(s2)));

            case OrderByVariable.Access:
            {
                if (order is OrderByStructTime)
                {
                    return(DateExtractor.GetVariable(FileInnerVariable.GetAccess(s1), (order as OrderByStructTime).GetTimeVariable()) ==
                           DateExtractor.GetVariable(FileInnerVariable.GetAccess(s2), (order as OrderByStructTime).GetTimeVariable()));
                }
                else if (order is OrderByStructDate)
                {
                    return(DateExtractor.DateToInt(FileInnerVariable.GetAccess(s1)).Equals(
                               DateExtractor.DateToInt(FileInnerVariable.GetAccess(s2))));
                }
                else if (order is OrderByStructClock)
                {
                    return(DateExtractor.ClockToInt(FileInnerVariable.GetAccess(s1)).Equals(
                               DateExtractor.ClockToInt(FileInnerVariable.GetAccess(s2))));
                }
                else
                {
                    return(FileInnerVariable.GetAccess(s1).Equals(FileInnerVariable.GetAccess(s2)));
                }
            }

            case OrderByVariable.Creation:
            {
                if (order is OrderByStructTime)
                {
                    return(DateExtractor.GetVariable(FileInnerVariable.GetCreation(s1), (order as OrderByStructTime).GetTimeVariable()) ==
                           DateExtractor.GetVariable(FileInnerVariable.GetCreation(s2), (order as OrderByStructTime).GetTimeVariable()));
                }
                else if (order is OrderByStructDate)
                {
                    return(DateExtractor.DateToInt(FileInnerVariable.GetCreation(s1)).Equals(
                               DateExtractor.DateToInt(FileInnerVariable.GetCreation(s2))));
                }
                else if (order is OrderByStructClock)
                {
                    return(DateExtractor.ClockToInt(FileInnerVariable.GetCreation(s1)).Equals(
                               DateExtractor.ClockToInt(FileInnerVariable.GetCreation(s2))));
                }
                else
                {
                    return(FileInnerVariable.GetCreation(s1).Equals(FileInnerVariable.GetCreation(s2)));
                }
            }

            case OrderByVariable.Modification:
            {
                if (order is OrderByStructTime)
                {
                    return(DateExtractor.GetVariable(FileInnerVariable.GetModification(s1), (order as OrderByStructTime).GetTimeVariable()) ==
                           DateExtractor.GetVariable(FileInnerVariable.GetModification(s2), (order as OrderByStructTime).GetTimeVariable()));
                }
                else if (order is OrderByStructDate)
                {
                    return(DateExtractor.DateToInt(FileInnerVariable.GetModification(s1)).Equals(
                               DateExtractor.DateToInt(FileInnerVariable.GetModification(s2))));
                }
                else if (order is OrderByStructClock)
                {
                    return(DateExtractor.ClockToInt(FileInnerVariable.GetModification(s1)).Equals(
                               DateExtractor.ClockToInt(FileInnerVariable.GetModification(s2))));
                }
                else
                {
                    return(FileInnerVariable.GetModification(s1).Equals(FileInnerVariable.GetModification(s2)));
                }
            }
            }
            return(false);
        }