Exemple #1
0
        /// <summary>
        /// Get a Url's parameters leaving them url encoded
        /// </summary>
        /// <param name="urlString">The query string</param>
        /// <returns></returns>
        public static Dictionary<string, string> ParseQueryString(string urlString)
        {
            string queryString = new Uri(urlString).Query;
            Dictionary<string, string> kVParms = new Dictionary<string, string>();

            queryString.Replace("?", "");

            string[] keyValPairing = queryString.Split('&', '=');

            if ((keyValPairing.Length == 0) || (keyValPairing.Length % 2 != 0))
            {
                throw new Exception("Invalid input Url");
            }

            keyValPairing[0] = keyValPairing[0].TrimStart('?');

            for (int i = 0; i < keyValPairing.Length - 1; i++)
            {
                kVParms.Add(keyValPairing[i], keyValPairing[i + 1]);
            }

            return kVParms;
        }
        /// <summary>
        /// Called when the user looks for their League of Legends installation
        /// </summary>
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            //Disable patching if the user selects another league installation.
            PatchButton.IsEnabled = false;
            RemoveButton.IsEnabled = false;

            //Create a file dialog for the user to locate their league of legends installation.
            OpenFileDialog findLeagueDialog = new OpenFileDialog();
            findLeagueDialog.DefaultExt = ".exe";
            findLeagueDialog.Filter = "League of Legends Launcher|lol.launcher*.exe|Garena Launcher|lol.exe"; //Only show the league of legends executables

            string RiotPath = Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", "League of Legends");
            string GarenaPath = Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), "Program Files (x86)", "GarenaLoL", "GameData", "Apps", "LoL");

            //If they don't have League of Legends in the default path, look for Garena.
            if (!Directory.Exists(RiotPath))
                findLeagueDialog.InitialDirectory = Path.GetFullPath(GarenaPath);
            else
                findLeagueDialog.InitialDirectory = Path.GetFullPath(RiotPath);

            bool? selectedExectuable = findLeagueDialog.ShowDialog();

            if (selectedExectuable == false || selectedExectuable == null)
                return;

            //Remove the executable from the location
            Uri Location = new Uri(findLeagueDialog.FileName);
            string SelectedLocation = Location.LocalPath.Replace(Location.Segments.Last(), string.Empty);

            //Get the executable name to check for Garena
            string LastSegment = Location.Segments.Last();

            //If the file name is lol.exe, then it's garena
            if (!LastSegment.StartsWith("lol.launcher"))
            {
                type = ServerType.GARENA;
                RemoveButton.IsEnabled = true;
                PatchButton.IsEnabled = true;
                LocationTextbox.Text = Path.Combine(SelectedLocation, "Air");
            }
            else
            {
                //Check each RADS installation to find the latest installation
                string radsLocation = Path.Combine(SelectedLocation, "RADS", "projects", "lol_air_client", "releases");

                //Compare the version text with format x.x.x.x to get the largest directory
                var versionDirectories = Directory.GetDirectories(radsLocation);

                string finalDirectory = "";
                int BiggestVersion = 0;

                //Get the biggest version in the directory
                foreach (string x in versionDirectories)
                {
                    string CurrentVersion = new Uri(x).Segments.Last();
                    string[] VersionNumbers = CurrentVersion.Split('.');
                    for (int i = 0; i < VersionNumbers.Length; i++)
                    {
                        //Ensure that numbers like 0.0.2.1 are larger than 0.0.1.999
                        VersionNumbers[i] = VersionNumbers[i].PadLeft(3, '0');
                    }

                    int Version = Convert.ToInt32(string.Join("", VersionNumbers));

                    if (Version > BiggestVersion)
                    {
                        BiggestVersion = Version;
                        finalDirectory = x;
                    }
                }

                BackupVersion = BiggestVersion.ToString();

                //If the version isn't the intended version, show a message to the user. This is just a warning and probably can be ignored
                if (!_supportedVersions.Contains(BiggestVersion) && !Debugger.IsAttached)
                {
                    string Message = "This version of LESs may not support your version of League of Legends. Continue? This could harm your installation.";
                    MessageBoxResult versionMismatchResult = MessageBox.Show(Message, "Invalid Version", MessageBoxButton.YesNo);
                    if (versionMismatchResult == MessageBoxResult.No)
                        return;
                }

                type = ServerType.NORMAL;
                PatchButton.IsEnabled = true;
                RemoveButton.IsEnabled = true;

                LocationTextbox.Text = Path.Combine(finalDirectory, "deploy");
            }

            //Create the LESsBackup directory to allow the user to uninstall if they wish to later on.
            Directory.CreateDirectory(Path.Combine(LocationTextbox.Text, "LESsBackup"));
            Directory.CreateDirectory(Path.Combine(LocationTextbox.Text, "LESsBackup", BackupVersion));
        }
Exemple #3
0
        public static AmbiguousRule generate_rule(string url)
        {
            /*
            to solve issue #13
            there are a lot of second level domains, e.g. domain.info.au, domain.vic.au, ...
            so we check these rules:
            if url has only two parts (e.g. x.tld or www.x.tld) choose *.x.tld
            else if url has 3 parts or more(e.g. y.x.tld) and y!=www:
                check the following rules: (x = second part after tld)
                    1.(x is part of domain)
                        if len(x) > 4: assume that x is not part of extension, and choose  *.x.tld
                    2.(x is part of extension)
                        if len(x) <=2 (e.g. y.id.au) than choose *.y.x.tld
                        if x is in exceptions (com,net,org,edu,gov,asn.sch) choose *.y.x.tld
                            because many TLD's have second level domains on these, e.g. chap.sch.ir
                        if count(parts)==4 and first part is www: e.g. www.news.com.au, choose *.y.x.tld
                if none of the rules apply, the case is ambiguous, display both options in a context menu.
                    e.g. sealake.vic.au or something.fun.ir
            */

            // needed variables
            var domain = new Uri(url).Host;
            var parts = domain.Split('.');
            var count = parts.Length;
            var tld = parts.Last();
            var x = "";
            var y = "";
            try
            {
                x = parts[count - 2]; //second-level
                y = parts[count - 3]; //third-level
            }
            catch (IndexOutOfRangeException) { } // in case domain did not have 3 parts.. (e.g. localhost, google.com)

            // creating the patterns
            var rule_tld = String.Format("*.{0}.{1}", x, tld);
            var rule_second = String.Format("*.{0}.{1}.{2}", y, x, tld);
            var mode = 0; // 0 = error, 1=use rule_tld (*.x.tld), 2=use rule_second (*.y.x.tld), 3=ambiguous

            // this conditions are based on the long comment above
            if (count == 2 || (count == 3 && y == "www"))
                mode = 1;
            else if (count >= 3)
            {
                if (x.Length > 4)
                    mode = 1;
                else if (
                    (x.Length <= 2) ||
                    ((new[] { "com", "net", "org", "edu", "gov", "asn", "sch" }).Contains(x)) ||
                    (count == 4 && parts[0] == "www")
                    )
                    mode = 2;
                else
                    mode = 3;
            }

            return new AmbiguousRule()
            {
                tld_rule = rule_tld,
                second_rule = rule_second,
                mode = mode
            };
        }
Exemple #4
0
        private void AppsList_SetContent(IEnumerable<string> sections)
        {
            Image defIcon = Resources.PortableAppsBox;
            var index = 0;
            var icoDbPath = Path.Combine(HomeDir, "Assets\\icon.db");
            byte[] icoDb = null;
            byte[] swIcoDb = null;
            try
            {
                icoDb = File.ReadAllBytes(icoDbPath);
                if (!string.IsNullOrEmpty(_swSrv) && !string.IsNullOrEmpty(_swUsr) && !string.IsNullOrEmpty(_swPwd))
                    swIcoDb = NetEx.Transfer.DownloadData($"{_swSrv}/AppIcon.db", _swUsr, _swPwd);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            foreach (var section in sections)
            {
                var nam = Ini.Read(section, "Name", AppsDbPath);
                var des = Ini.Read(section, "Description", AppsDbPath);
                var cat = Ini.Read(section, "Category", AppsDbPath);
                var ver = Ini.Read(section, "Version", AppsDbPath);
                var pat = Ini.Read(section, "ArchivePath", AppsDbPath);
                var siz = Ini.ReadLong(section, "InstallSize", 1, AppsDbPath) * 1024 * 1024;
                var adv = Ini.ReadBoolean(section, "Advanced", AppsDbPath);
                var src = "si13n7.com";
                if (pat.StartsWithEx("http"))
                    try
                    {
                        var tmpHost = new Uri(pat).Host;
                        var tmpSplit = tmpHost.Split('.');
                        src = tmpSplit.Length >= 3 ? string.Join(".", tmpSplit[tmpSplit.Length - 2], tmpSplit[tmpSplit.Length - 1]) : tmpHost;
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        continue;
                    }

                // Description filter
                switch (section)
                {
                    case "LibreCADPortable":
                        des = des.LowerText("tool");
                        break;
                    case "Mp3spltPortable":
                        des = des.UpperText("mp3", "ogg");
                        break;
                    case "SumatraPDFPortable":
                        des = des.LowerText("comic", "book", "e-", "reader");
                        break;
                    case "WinCDEmuPortable":
                        des = des.UpperText("cd/dvd/bd");
                        break;
                    case "WinDjViewPortable":
                        des = des.UpperText("djvu");
                        break;
                }
                des = $"{des.Substring(0, 1).ToUpper()}{des.Substring(1)}";

                var item = new ListViewItem(nam) { Name = section };
                item.SubItems.Add(des);
                item.SubItems.Add(ver);
                item.SubItems.Add(siz.FormatDataSize(true, true, true));
                item.SubItems.Add(src);
                item.ImageIndex = index;
                if (section.EndsWith("###") && (string.IsNullOrEmpty(_swSrv) || string.IsNullOrEmpty(_swUsr) || string.IsNullOrEmpty(_swPwd)))
                    continue;
                if (!string.IsNullOrWhiteSpace(cat))
                {
                    try
                    {
                        var nameHash = (section.EndsWith("###") ? section.Substring(0, section.Length - 3) : section).EncryptToMd5();
                        if (icoDb == null)
                            throw new ArgumentNullException(nameof(icoDb));
                        foreach (var db in new[] { icoDb, swIcoDb })
                        {
                            if (db == null)
                                continue;
                            using (var stream = new MemoryStream(db))
                                try
                                {
                                    using (var archive = new ZipArchive(stream))
                                        foreach (var entry in archive.Entries)
                                        {
                                            if (entry.Name != nameHash)
                                                continue;
                                            imgList.Images.Add(nameHash, Image.FromStream(entry.Open()));
                                            break;
                                        }
                                }
                                catch (Exception ex)
                                {
                                    Log.Write(ex);
                                }
                        }
                        if (!imgList.Images.ContainsKey(nameHash))
                            throw new PathNotFoundException(icoDbPath + ":" + nameHash + ">>" + section);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        imgList.Images.Add(defIcon);
                    }
                    try
                    {
                        if (!section.EndsWith("###"))
                            foreach (ListViewGroup gr in appsList.Groups)
                            {
                                if ((adv || !Lang.GetText("en-US", gr.Name).EqualsEx(cat)) && !Lang.GetText("en-US", gr.Name).EqualsEx("*Advanced"))
                                    continue;
                                appsList.Items.Add(item).Group = gr;
                                break;
                            }
                        else
                            appsList.Items.Add(item).Group = appsList.Groups[appsList.Groups.Count - 1];
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                    }
                }
                index++;
            }
            appsList.SmallImageList = imgList;
            AppsList_ShowColors();
            appStatus.Text = string.Format(Lang.GetText(appStatus), appsList.Items.Count, appsList.Items.Count == 1 ? Lang.GetText("App") : Lang.GetText("Apps"));
        }
Exemple #5
0
        static NameValueCollection ParseQueryString(string url)
        {
            url = url.Replace("?", "");

            var parameters = new NameValueCollection();

            foreach (var parameter in url.Split('&').Where(p => p.Contains('=')).Select(p => p.Split('=')))
            {
                parameters.Add(parameter[0], parameter[1]);
            }

            return parameters;
        }
Exemple #6
0
        /// <summary>
        /// Initializes the name of the running service.
        /// </summary>
        private static void InitializeRunningServiceName()
        {
            try
            {
                // Usually, the application run into IIS, so HttpContext is initialized.
                HttpContext context = HttpContext.Current;
                if (context != null && context.Request != null)
                {
                    RunningServiceName = context.Request.ApplicationPath.Trim('/');
                }
                else
                {
                    string path = new System.Uri(typeof(ServiceConfiguration).Assembly.CodeBase).LocalPath;

                    // In case that we run into the debugger of Visual studio, web site might be located into a temporary folder.
                    string tempAspNetFiles = Path.Combine(Path.GetTempPath(), "Temporary ASP.NET Files" + Path.DirectorySeparatorChar);

                    if (path.StartsWith(tempAspNetFiles, StringComparison.OrdinalIgnoreCase))
                    {
                        path = path.Substring(tempAspNetFiles.Length);

                        char firstChar  = path[0];
                        int  foundIndex = path.IndexOfAny(new char[] { System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }, 0);

                        if (foundIndex > 0)
                        {
                            path = path.Substring(0, foundIndex);
                        }
                    }
                    else
                    {
                        // Run in the context of automated tests.
                        string[] pathSplitted = path.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                        int      index        = pathSplitted.Length;
                        if (index > 1)
                        {
                            index -= 2;
                            if (index > 1 && (string.Equals(pathSplitted[index], "Debug", StringComparison.OrdinalIgnoreCase) ||
                                              string.Equals(pathSplitted[index], "Release", StringComparison.OrdinalIgnoreCase)))
                            {
                                index--;
                            }
                            if (index > 1 && string.Equals(pathSplitted[index], "bin", StringComparison.OrdinalIgnoreCase))
                            {
                                index--;
                            }
                        }
                        else
                        {
                            index = 0;
                        }

                        path = pathSplitted[index];
                    }

                    if (!string.IsNullOrEmpty(path))
                    {
                        RunningServiceName = path;
                    }
                    else
                    {
                        RunningServiceName = "PIS.Ground.Core";
                    }
                }
            }
            catch
            {
                RunningServiceName = "PIS.Ground.Core";
            }
        }