private PermissionsWindow(Window owner, SmartItem[] items)
        {
            this.Owner = owner;
            InitializeComponent();

            this.Items = items;

            TextBoxPath.Text          = ClientHelper.CurrentPath;
            LabelPermissionDgit.Text  = items[0].Permissions;
            TextBoxNewPermission.Text = items[0].Permissions;

            LabelPermission.Text = PermParser.GetLetters(items[0].Permissions);

            for (int i = 0; i < items.Length; i++)
            {
                if (!TextBoxFiles.Text.NullEmpty())
                {
                    TextBoxFiles.Text += AppLanguage.Get("LangTextSpaceComma");
                }
                TextBoxFiles.Text += items[i].ItemName;
            }
        }
Example #2
0
            internal static async Task <SmartItem[]> ParseAsync(FTPClient client, string path, string rawItems)
            {
                if ((rawItems == null) || client.IsCanceled)
                {
                    return(null);
                }

                List <SmartItem> list = new List <SmartItem>();

                if (rawItems.Length > 8)
                {
                    await Task.Run(() =>
                    {
                        SmartItem item;
                        Match match;
                        DateTime date;
                        string[] dateFormats;
                        string nowYear  = ' ' + DateTime.UtcNow.Year.StringInv();
                        string modified = string.Empty;

                        try
                        {
                            if (!client.IsUnix.HasValue)
                            {
                                client.IsUnix = !isWinRegex.IsMatch(rawItems.Substring(0, 8));
                            }

                            if (client.IsUnix.Value)
                            {
                                match       = unix.Match(rawItems);
                                dateFormats = dateFormatsUnix;
                            }
                            else
                            {
                                match       = win.Match(rawItems);
                                dateFormats = dateFormatsWin;
                            }

                            rawItems = null;

                            int x = -1;
                            while (match.Success)
                            {
                                if (client.IsCanceled)
                                {
                                    break;
                                }

                                item     = new SmartItem(match.Groups["Name"].Value, path);
                                modified = match.Groups["Modified"].Value;
                                if (client.IsUnix.Value)
                                {
                                    int t = modified.Index(":");
                                    if ((t > 0) && (t > 3))
                                    {
                                        modified = modified.Insert(6, nowYear);
                                    }

                                    switch (match.Value[0])
                                    {
                                    case 'd':
                                        if ((match.Groups["Name"].Value.Length < 3) && ((match.Groups["Name"].Value == ".") || (match.Groups["Name"].Value == "..")))
                                        {
                                            match = match.NextMatch(); continue;
                                        }
                                        break;

                                    case 'l':
                                        item        = new SmartItem(match.Groups["Name"].Value.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim(), path);
                                        item.IsLink = true;
                                        break;

                                    default:
                                        item.IsFile = true;
                                        break;
                                    }

                                    item.Permissions = PermParser.ParseText(match.Groups["Permissions"].Value);
                                }
                                else
                                {
                                    item.IsFile = (match.Groups["Length"].Value != "<DIR>");
                                }

                                if (modified.DateInvCulture(dateFormats, out date))
                                {
                                    item.Modified = date.ToLocalTime().Ticks;
                                }

                                if (item.IsFile)
                                {
                                    item.Length = match.Groups["Length"].Value.Long();
                                    list.Add(item);
                                }
                                else
                                {
                                    list.Insert(++x, item);
                                }

                                match = match.NextMatch();
                            }
                        }
                        catch (Exception exp) { ExceptionHelper.Log(exp); }
                        match = null;
                    });
                }

                return(client.IsCanceled ? null : list.ToArray());
            }