Example #1
0
        public static void ParseCommand(string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                return;
            }

            string[] commandParts = command.Split(' ');
            if (commandParts.Length >= 2 && commandParts[0].ToLower() == "ls" && FMLib.isDirectoryExist(commandParts[1]))
            {
                currentDirectory = FMLib.GetFullPath(commandParts[1]);
                if (commandParts.Length == 4 && commandParts[2] == "-p" && Int32.TryParse(commandParts[3], out int p))
                {
                    page = p;
                }
                else
                {
                    page = 1;
                }
            }
            if (commandParts.Length >= 2 && commandParts[0].ToLower() == "cd" && FMLib.isDirectoryExist(commandParts[1]))
            {
                currentDirectory = FMLib.GetFullPath(commandParts[1]);
                FMLib.ChangeDirectory(FMLib.GetFullPath(commandParts[1]));
                page = 1;
            }
            if (commandParts.Length == 2 && commandParts[0].ToLower() == "info")
            {
                currentInfoItem = FMLib.GetFullPath(commandParts[1]);
            }
            if (commandParts.Length == 3 && commandParts[0].ToLower() == "copy")
            {
                try
                {
                    FMLib.Copy(commandParts[1], commandParts[2]);
                }
                catch (Exception ex)
                {
                    WriteEvent(ex.Message);
                }
            }
            if (commandParts.Length == 2 && commandParts[0].ToLower() == "delete")
            {
                try
                {
                    FMLib.Delete(commandParts[1]);
                }
                catch (Exception ex)
                {
                    WriteEvent(ex.Message);
                }
            }
        }
Example #2
0
        static List <string> history   = new List <string>(); // saved commands typed by user

        public static void Run()
        {
            LoadSettings();

            string command = null;

            while (command != "exit")
            {
                Console.Clear();

                ContentPanel content = new ContentPanel();
                try
                {   //по идее это надо заталкать в конструктор, но мы их еще не проходили, поэтому оставлю тут
                    content.folderPath    = FMLib.GetFullPath(currentDirectory);
                    content.folderContent = FormatDirectoryListing(content.folderPath, page);
                }
                catch (Exception ex)
                {
                    content.folderContent = new List <string>();
                    WriteEvent(ex.Message);
                }

                InfoPanel info = new InfoPanel()
                {
                    path = currentInfoItem
                };
                try
                {   //и это тоже
                    info.attr      = FMLib.GetAttributes(info.path);
                    info.dataTimes = FMLib.GetTimes(info.path);
                    info.size      = FMLib.GetSizeOnDisk(info.path);
                }
                catch
                {
                    info = null;
                }

                ShowGUI(content, info);
                //command = Console.ReadLine();
                command = ReadCommand();
                ParseCommand(command);
            }

            SaveSettings();
        }
Example #3
0
        public static List <string> FormatDirectoryListing(string path, int page = 1)
        {
            List <string> list = new List <string>();

            foreach (var item in FMLib.GetFolderContent(path))
            {
                if (item.Name == ".")
                {
                    continue;
                }
                if ((item.Attributes & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
                {
                    list.Add("[" + item.Name + "]");
                }
                else
                {
                    list.Add(item.Name);
                }
            }
            list.Sort();

            if (page - 1 > list.Count / pageSize)
            {
                page = 1;
            }
            int start = (page - 1) * pageSize;
            int end   = Math.Min(page * pageSize, list.Count);

            var retValue = new List <string>();

            for (int i = start; i < end; i++)
            {
                retValue.Add(list[i]);
            }
            return(retValue);
        }
Example #4
0
        private static void LoadSettings()
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (config.HasFile)
            {
                pageSize = Convert.ToInt32(config.AppSettings.Settings["pageSize"].Value);
            }
            var roaming = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
            var fileMap = new ExeConfigurationFileMap()
            {
                ExeConfigFilename = roaming.FilePath
            };

            config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            if (config.HasFile)
            {
                if (config.AppSettings.Settings.AllKeys.Contains("currentDirectory") &&
                    FMLib.isDirectoryExist(config.AppSettings.Settings["currentDirectory"].Value))
                {
                    currentDirectory = config.AppSettings.Settings["currentDirectory"].Value;
                    FMLib.ChangeDirectory(config.AppSettings.Settings["currentDirectory"].Value);
                }

                if (config.AppSettings.Settings.AllKeys.Contains("currentInfoItem"))
                {
                    currentInfoItem = config.AppSettings.Settings["currentInfoItem"].Value;
                }

                if (config.AppSettings.Settings.AllKeys.Contains("page"))
                {
                    page = Convert.ToInt32(config.AppSettings.Settings["page"].Value);
                }
            }
        }