Exemplo n.º 1
0
        internal static async Task load()
        {
            if (!IsEnabled)
            {
                return;
            }

            await Task.Run(() =>
            {
                string[] lines       = FileHelper.ReadAll(FilePath).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                HistoryItem[] _items = new HistoryItem[lines.Length];

                Regex regex           = new Regex(@"\{([^\}]+)\}", RegexOptions.Compiled);
                MatchCollection match = null;

                for (int i = 0; i < lines.Length; i++)
                {
                    try
                    {
                        match = regex.Matches(lines[i]);
                        if (match.Count == 7)
                        {
                            DateTime dateTime = new DateTime(match[6].Groups[1].Value.Long());
                            _items[i]         = new HistoryItem(match[0].Groups[1].Value, match[1].Groups[1].Value, match[2].Groups[1].Value, match[3].Groups[1].Value, match[4].Groups[1].Value, match[5].Groups[1].Value, dateTime);
                        }
                    }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }
                }

                items = new ObservableCollection <HistoryItem>(_items);
            });
        }
Exemplo n.º 2
0
        internal static SmartItem[] SelectedItems(this ListView list, SmartCollection collection)
        {
            if (list.SelectedItems.Count == 0)
            {
                return(null);
            }
            SmartItem[] items = new SmartItem[list.SelectedItems.Count];

            try { list.SelectedItems.CopyTo(items, 0); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            list.UnselectAll();
            if (items.Length == 0)
            {
                return(null);
            }

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

            for (int i = 0; i < items.Length; i++)
            {
                if ((items[i].Status == ItemStatus.CreateError) || ((items[i].Status == ItemStatus.UploadError) && (items[i].Length == 0)))
                {
                    AppMessage.Add("\"" + items[i].ItemName + "\" Dose not Exist.", MessageType.Warning);
                    collection.Remove(items[i]);
                }
                else
                {
                    itemsList.Add(items[i]);
                }
            }

            return((itemsList.Count > 0) ? itemsList.ToArray() : null);
        }
Exemplo n.º 3
0
        protected static Stream setDeflateStream(Stream stream, bool isRead)
        {
            if (stream == null)
            {
                return(null);
            }
            DeflateStream s = null;

            try
            {
                if (isRead)
                {
                    s = new DeflateStream(stream, CompressionMode.Decompress, false);
                    s.BaseStream.ReadByte();
                    s.BaseStream.ReadByte();
                }
                else
                {
                    s = new DeflateStream(stream, CompressionMode.Compress, false);
                    s.BaseStream.WriteByte(120);
                    s.BaseStream.WriteByte(218);
                }
            }
            catch (Exception exp) { s = null; ExceptionHelper.Log(exp); }

            return(s);
        }
Exemplo n.º 4
0
        protected async Task <SmartItem[]> _getLocalItemsAsync(string path)
        {
            List <SmartItem> items = new List <SmartItem>();

            await Task.Run(() =>
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                FileInfo[] files  = null;
                try
                {
                    files = dir.GetFiles();
                    for (int i = 0; i < files.Length; i++)
                    {
                        items.Add(new SmartItem(files[i]));
                    }
                }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
                files = null;

                DirectoryInfo[] subDirs = null;
                try
                {
                    subDirs = dir.GetDirectories();
                    for (int i = 0; i < subDirs.Length; i++)
                    {
                        items.Add(new SmartItem(subDirs[i]));
                    }
                }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
                subDirs = null;
                dir     = null;
            });

            return(items.ToArray());
        }
Exemplo n.º 5
0
        internal static string Decrypt(string str)
        {
            if (str.NullEmpty())
            {
                return(string.Empty);
            }

            try
            {
                string[] splited   = str.Split(new Char[] { '(' });
                byte[]   decrypted = Convert.FromBase64String(splited[1].Remove(0, 1).Insert(0, splited[0][0].ToString()));

                using (TripleDES TDES = TripleDES.Create())
                {
                    TDES.Key = keyBytes;
                    TDES.IV  = Convert.FromBase64String(splited[0].Remove(0, 1).Insert(0, splited[1][0].ToString()));

                    using (MemoryStream MS = new MemoryStream())
                    {
                        CryptoStream CS = new CryptoStream(MS, TDES.CreateDecryptor(), CryptoStreamMode.Write);
                        CS.Write(decrypted, 0, decrypted.Length);
                        CS.Close();

                        return(Encoding.UTF8.GetString(MS.ToArray()));
                    }
                }
            }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            return(string.Empty);
        }
Exemplo n.º 6
0
 internal static void WriteAll(string path, string text)
 {
     if (text != null)
     {
         try { File.WriteAllText(path, text, Encoding.UTF8); }
         catch (Exception exp) { ExceptionHelper.Log(exp); }
     }
 }
Exemplo n.º 7
0
        internal static FileStream Create(string path)
        {
            FileStream fs = null;

            try { fs = File.Create(path); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            return(fs);
        }
Exemplo n.º 8
0
        internal static string GetPath(string path)
        {
            string name = null;

            try { name = Path.GetDirectoryName(path); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            return(name);
        }
Exemplo n.º 9
0
        internal static async Task Load()
        {
            if (isLoaded)
            {
                return;
            }

            await Task.Run(() =>
            {
                string[] lines = FileHelper.ReadAll(FilePath).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                Items          = new List <UserInfo>(lines.Length);

                Regex regex = new Regex(@"(?<Variable>[^""]+)""(?<Value>[^""]*)""\s*", RegexOptions.Compiled);

                for (int i = 0; i < lines.Length; i++)
                {
                    UserInfo user = new UserInfo();
                    try
                    {
                        MatchCollection matches = regex.Matches(lines[i]);
                        for (int j = 0; j < matches.Count; j++)
                        {
                            switch (matches[j].Groups["Variable"].Value)
                            {
                            case "Host": user.Host = matches[j].Groups["Value"].Value; break;

                            case "UserName": user.UserName = matches[j].Groups["Value"].Value; break;

                            case "Password": user.Password = matches[j].Groups["Value"].Value; break;

                            case "Port": user.Port = matches[j].Groups["Value"].Value.Int(); break;

                            case "Encryption": user.Encryption = matches[j].Groups["Value"].Value.Int(); break;

                            case "Protocol": user.Protocol = matches[j].Groups["Value"].Value.Int(); break;

                            case "UTF8": user.UTF8 = matches[j].Groups["Value"].Value.Int(); break;

                            case "MODEZ": user.MODEZ = matches[j].Groups["Value"].Value.Int(); break;

                            case "Proxy": user.Proxy = matches[j].Groups["Value"].Value.Int(); break;

                            case "Cache": user.Cache = matches[j].Groups["Value"].Value.Int(); break;

                            case "Selected": user.Selected = matches[j].Groups["Value"].Value.True(); break;
                            }
                        }
                        Items.Add(user);
                    }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }
                }
            });

            isLoaded = true;
        }
Exemplo n.º 10
0
        internal static IEnumerable <string> ReadLines(string path)
        {
            IEnumerable <string> text = new List <string>(0);

            if (Exists(path))
            {
                try { text = File.ReadLines(path, Encoding.UTF8); }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            }

            return(text);
        }
Exemplo n.º 11
0
        private static void _set()
        {
            try { SysShortDateFormat = Registry.CurrentUser.OpenSubKey(@"Control Panel\International", false).GetValue("sShortDate").ToString(); }
            catch (Exception exp) { SysShortDateFormat = "d/M/yyyy"; ExceptionHelper.Log(exp); }

            try { SysTimeFormat = Registry.CurrentUser.OpenSubKey(@"Control Panel\International", false).GetValue("sTimeFormat").ToString(); }
            catch (Exception exp) { SysTimeFormat = "h:mm:ss tt"; ExceptionHelper.Log(exp); }

            try { SysShortTimeFormat = Registry.CurrentUser.OpenSubKey(@"Control Panel\International", false).GetValue("sShortTime").ToString(); }
            catch (Exception exp) { SysShortTimeFormat = "h:mm tt"; ExceptionHelper.Log(exp); }
            SysDateTimeFormat = SysShortDateFormat + " " + SysTimeFormat;
        }
Exemplo n.º 12
0
        internal static bool Move(string from, string to)
        {
            if (Exists(from) && !Exists(to))
            {
                try { Directory.Move(from, to); }
                catch (Exception exp) { ExceptionHelper.Log(exp); return(false); }

                return(true);
            }

            return(false);
        }
Exemplo n.º 13
0
        internal static bool Seek(FileStream fs, long tbytes)
        {
            if (fs == null)
            {
                return(false);
            }

            try { fs.Seek(tbytes, SeekOrigin.Begin); }
            catch (Exception exp) { ExceptionHelper.Log(exp); return(false); }

            return(true);
        }
Exemplo n.º 14
0
        internal static async Task <SslStream> ConnectAsync(Stream s, string server)
        {
            try
            {
                X509CertificateCollection clientCertColl = new X509CertificateCollection();
                SslStream sslStream = new SslStream(s, false, new RemoteCertificateValidationCallback(validate), null);
                await sslStream.AuthenticateAsClientAsync(server, clientCertColl, SslProtocols.Default, false);

                return(sslStream);
            }
            catch (Exception exp) { ExceptionHelper.Log(exp); }
            return(null);
        }
Exemplo n.º 15
0
        private static async Task <Socket> ConnectHttpAsync(string host, int port)
        {
            //TODO: need testing
            Socket socket = null;

            try
            {
                socket = await SocketHelper.ConnectAsync(host, port);

                if (socket == null)
                {
                    return(null);
                }

                await Task.Run(() => { socket.Send(Encoding.UTF8.GetBytes("CONNECT " + host + ":" + port + " HTTP/1.0\r\n\r\n")); });

                byte[] recvBuffer = new byte[39];
                string respond = string.Empty;
                int    received, tbytes = 0;

                await Task.Run(() =>
                {
                    do
                    {
                        received = 0;
                        received = socket.Receive(recvBuffer);
                        if (received == 0)
                        {
                            break;
                        }

                        tbytes  += received;
                        respond += Encoding.ASCII.GetString(recvBuffer, 0, recvBuffer.Length);
                        //if (respond.Contains("\r\n\r\n")) break;
                    }while ((tbytes > 0) && (tbytes < 39));
                });

                if (respond.Contains("200"))
                {
                    return(socket);
                }
            }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            if (socket != null)
            {
                socket.Close();
            }

            return(null);
        }
Exemplo n.º 16
0
        internal static bool Create(string path)
        {
            if (Exists(path))
            {
                return(true);
            }
            else
            {
                try { Directory.CreateDirectory(path); return(true); }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            }

            return(false);
        }
Exemplo n.º 17
0
        internal static async Task AppendTextAsync(string path, string text)
        {
            if ((text == null) || (text.Length == 0))
            {
                return;
            }

            try
            {
                using (StreamWriter sw = File.AppendText(path))
                    await sw.WriteLineAsync(text);
            }
            catch (Exception exp) { ExceptionHelper.Log(exp); }
        }
Exemplo n.º 18
0
        private static void _set()
        {
            try
            {
                Guid imageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");

                int r = SafeNativeMethods.SHGetImageList((int)ImageListIconSize.ExtraLarge, ref imageListGuid, out iImageList);
                if (r != 0)
                {
                    iImageList = null;
                }
            }
            catch (Exception exp) { ExceptionHelper.Log(exp); }
        }
Exemplo n.º 19
0
        internal static SmartItem[] SelectedItems(this ListBox list)
        {
            if (list.SelectedItems.Count == 0)
            {
                return(null);
            }
            SmartItem[] items = new SmartItem[list.SelectedItems.Count];

            try { list.SelectedItems.CopyTo(items, 0); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            list.UnselectAll();

            return((items.Length > 0) ? items : null);
        }
Exemplo n.º 20
0
        internal static SmartItem SelectedItem(this ListView list)
        {
            if (list.SelectedItems.Count != 1)
            {
                return(null);
            }

            SmartItem item = null;

            try { item = list.SelectedItem as SmartItem; }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            list.UnselectAll();

            return(item);
        }
Exemplo n.º 21
0
        internal static string ReadAll(string path)
        {
            string text = string.Empty;

            if (Exists(path))
            {
                try
                {
                    using (StreamReader sr = new StreamReader(path, Encoding.UTF8))
                        text = sr.ReadToEnd();
                }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            }

            return(text);
        }
Exemplo n.º 22
0
        internal static string GetParentPath(string path)
        {
            if (Exists(path))
            {
                try
                {
                    DirectoryInfo dir = new DirectoryInfo(path);
                    if ((dir != null) && (dir.Parent != null))
                    {
                        return(dir.Parent.FullName);
                    }
                }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            }

            return(null);
        }
Exemplo n.º 23
0
        protected static SmartItem InsertItem(SmartItem item, bool checkPath = true)
        {
            if (checkPath && (item.ItemFolder != BrowsedPath))
            {
                return(null);
            }

            try
            {
                int id = Items.GetLastFolderID();
                Items.Insert(id, item);
                return(Items[id]);
            }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            return(null);
        }
Exemplo n.º 24
0
        internal static Visual GetVisual(this FrameworkElement Owner, string name)
        {
            if (visualList.ContainsKey(name))
            {
                return(visualList[name]);
            }

            Visual visual = Owner.Resources[name] as Visual;

            Task.Run(() =>
            {
                try { visualList.Add(name, visual); }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            });

            return(visual);
        }
Exemplo n.º 25
0
        internal static async Task <bool> SetItemsAsync(string path)
        {
            if (!IsConnected)
            {
                return(false);
            }

            stopwatch.Reset();
            stopwatch.Start();
            LastPath     = CurrentPath;
            Counts.Items = string.Empty;

            if (await mainClient.SetItemsAsync(path))
            {
                CurrentPath    = NetworkClient.BrowsedPath;
                Counts.Files   = Items.Files;
                Counts.Folders = Items.Folders;
                Counts.Update();

                stopwatch.Stop();
                string seconds = "({0:#0.0#}s)".FormatC((double)stopwatch.ElapsedMilliseconds / 1000);

                if (CurrentPath == "/")
                {
                    AppMessage.Add("/ Listed Successfully " + seconds, MessageType.Info);
                }
                else
                {
                    try { AppMessage.Add(new Regex("/(?<DIR>[^/]+)/?$", RegexOptions.Compiled).Match(CurrentPath).Groups["DIR"].Value + " Listed Successfully " + seconds, MessageType.Info); }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }
                }

                return(true);
            }
            else
            {
                AppMessage.Add("Unable To List Server items.", MessageType.Error);
            }

            stopwatch.Stop();
            return(false);
        }
Exemplo n.º 26
0
        internal static BitmapSource Get(string source, bool isFile, string extension, bool isLink)
        {
            bool Local    = !source.Starts("/");
            bool iconOnly = (!Local || !extension.NullEmpty() && !NoExtCache.Contains(extension));

            extension = (extension.NullEmpty() ? "dummy" : extension);
            string name = iconOnly ? (isFile ? extension : "folder") : source;

            if (iconsList.ContainsKey(name))
            {
                return(iconsList[name]);
            }

            BitmapSource icon = null;

            if (!Local)
            {
                if (isFile)
                {
                    ImageList.Get(ref icon, "." + extension, ImageList.SHFlags.ICON | ImageList.SHFlags.SYSICONINDEX | ImageList.SHFlags.USEFILEATTRIBUTES);
                }
                else
                {
                    source = DirectoryHelper.Temp;
                    Local  = true;
                }
            }

            if (Local)
            {
                ImageFactory.Get(ref icon, source, (iconOnly ? ImageFactory.SIIGBF.ICONONLY : 0) | ImageFactory.SIIGBF.RESIZETOFIT);
            }

            Task.Run(() =>
            {
                try { iconsList.Add(name, icon); }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            });

            return(icon);
        }
Exemplo n.º 27
0
        internal static BitmapSource Get(int source)
        {
            string name = source.String();

            if (iconsList.ContainsKey(name))
            {
                return(iconsList[name]);
            }

            BitmapSource icon = null;

            ImageList.Get(ref icon, source, ImageList.SHFlags.ICON | ImageList.SHFlags.DISPLAYNAME | ImageList.SHFlags.SYSICONINDEX | ImageList.SHFlags.PIDL);

            Task.Run(() =>
            {
                try { iconsList.Add(name, icon); }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            });

            return(icon);
        }
Exemplo n.º 28
0
        internal static MessageItem[] SelectedMessages(this ListView list)
        {
            if (list.SelectedItems.Count == 0)
            {
                return(null);
            }
            MessageItem[] items = new MessageItem[list.SelectedItems.Count];

            try { list.SelectedItems.CopyTo(items, 0); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }
            if (items.Length == 0)
            {
                return(null);
            }

            Array.Sort(items, delegate(MessageItem message1, MessageItem message2)
            {
                return(message1.DateTicks.CompareTo(message2.DateTicks));
            });

            return(items);
        }
Exemplo n.º 29
0
        internal static SmartItem GetServerItem(string name, string path, SmartItem item = null, bool clearCacheAfter = false)
        {
            if ((path != BrowsedPath) || ((Items.Count == 0) && (item == null)))
            {
                return(null);
            }

            int id = Items.GetID(path + name);

            if (clearCacheAfter)
            {
                Items.ClearCache();
            }

            if (id == -1)
            {
                if (item != null)
                {
                    return(InsertItem(item, false));
                }
            }
            else
            {
                try
                {
                    if (item != null)
                    {
                        Items[id] = item;
                    }
                    return(Items[id]);
                }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            }

            return(null);
        }
Exemplo n.º 30
0
        internal static DriveInfo[] GetDrives()
        {
            DriveInfo[] drives = new DriveInfo[] { };

            try { drives = DriveInfo.GetDrives(); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            if (drives.Length == 0)
            {
                return(drives);
            }

            List <DriveInfo> drivesList = new List <DriveInfo>(drives.Length);

            for (int i = 0; i < drives.Length; i++)
            {
                if (DirectoryHelper.Exists(drives[i].Name))
                {
                    drivesList.Add(drives[i]);
                }
            }

            return(drivesList.ToArray());
        }