Example #1
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 + ".");
                }
            }
        }
Example #2
0
        public override bool ToBool()
        {
            string file      = arg0.ToString();
            string directory = arg1.ToString();

            if (file.Equals("") || directory.Equals(""))
            {
                return(false);
            }

            return(FileInnerVariable.ExistInside(file, directory));
        }
Example #3
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 + ".");
                }
            }
        }
Example #4
0
        public void Run()
        {
            string location = RuntimeVariables.GetInstance().GetWholeLocation();

            IntPtr nativeFolder;
            uint   psfgaoOut;

            SHParseDisplayName(location, IntPtr.Zero, out nativeFolder, 0, out psfgaoOut);

            // location not exists
            if (nativeFolder == IntPtr.Zero)
            {
                return;
            }

            List <string> selected = new List <string>();

            foreach (string str in list.ToList())
            {
                if (FileInnerVariable.Exist(str))
                {
                    selected.Add(str);
                }
            }

            // escape if there is nothing to select
            if (selected.Count == 0)
            {
                return;
            }

            //fill array of files and directories
            IntPtr[] fileArray = new IntPtr[selected.Count];
            for (int i = 0; i < selected.Count; i++)
            {
                SHParseDisplayName(System.IO.Path.Combine(location, selected[i]), IntPtr.Zero, out fileArray[i], 0, out psfgaoOut);
                Logger.GetInstance().LogCommand("Select " + selected[i]);
            }

            SHOpenFolderAndSelectItems(nativeFolder, (uint)fileArray.Length, fileArray, 0);

            // free memory
            Marshal.FreeCoTaskMem(nativeFolder);
            for (int i = 0; i < selected.Count; i++)
            {
                Marshal.FreeCoTaskMem(fileArray[i]);
            }
        }
Example #5
0
        public override DateTime ToTime()
        {
            string file = arg0.ToString();

            return(FileInnerVariable.GetModification(file));
        }
Example #6
0
        public override decimal ToNumber()
        {
            string file = arg0.ToString();

            return(FileInnerVariable.GetSize(file));
        }
Example #7
0
        public override bool ToBool()
        {
            string file = arg0.ToString();

            return(FileInnerVariable.Exist(file));
        }
Example #8
0
        public override string ToString()
        {
            string file = arg0.ToString();

            return(FileInnerVariable.GetFullname(file));
        }
Example #9
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);
        }
Example #10
0
        public override string ToString()
        {
            string file = arg0.ToString();

            return(FileInnerVariable.GetExtension(file));
        }
Example #11
0
        public override DateTime ToTime()
        {
            string file = arg0.ToString();

            return(FileInnerVariable.GetAccess(file));
        }
Example #12
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);
        }