Example #1
0
        static void CloseArchive(TarArchive archive)
        {
#if WIN32
            archive?.CloseArchive();
#else
            archive?.Close();
#endif
        }
Example #2
0
 private void UnTarFile(Stream InputStream, string BasePath, bool Compressed)
 {
     EnterMethod();
     try
     {
         Directory.CreateDirectory(BasePath);
         if (Compressed)
         {
             InputStream = new GZipOutputStream(InputStream);
         }
         TarArchive archive = TarArchive.CreateInputTarArchive(InputStream);
         archive.ExtractContents(BasePath);
         archive.CloseArchive();
     }
     catch (Exception E)
     {
         SendError(E);
         throw;
     }
 }
Example #3
0
        public static bool ExtractTgz(string strSourceFilename, string strDestFolder)
        {
            try
            {
                Stream inStream   = File.OpenRead(strSourceFilename);
                Stream gzipStream = new GZipInputStream(inStream);

                TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                tarArchive.ExtractContents(strDestFolder);
                tarArchive.CloseArchive();

                gzipStream.Close();
                inStream.Close();

                return(true);
            } catch (Exception)
            {
                // Log error
                return(false);
            }
        }
Example #4
0
        public void EmptyTar()
        {
            MemoryStream ms     = new MemoryStream();
            TarArchive   tarOut = TarArchive.CreateOutputTarArchive(ms);

            tarOut.CloseArchive();

            Assert.IsTrue(ms.GetBuffer().Length > 0, "Archive size must be > zero");
            Assert.AreEqual(ms.GetBuffer().Length % tarOut.RecordSize, 0, "Archive size must be a multiple of record size");

            MemoryStream ms2 = new MemoryStream();

            ms2.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
            ms2.Seek(0, SeekOrigin.Begin);

            TarArchive tarIn = TarArchive.CreateInputTarArchive(ms2);

            entryCount = 0;
            tarIn.ProgressMessageEvent += new ProgressMessageHandler(EntryCounter);
            tarIn.ListContents();
            Assert.AreEqual(0, entryCount, "Expected 0 tar entries");
        }
Example #5
0
        private void StartPatcher()
        {
            bgThread = new Thread(() =>
            {
                LogTextBox("Starting Patcher");

                WebClient client = new WebClient();

                #region Configure download bar
                client.DownloadProgressChanged += (o, e) =>
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        double bytesIn               = double.Parse(e.BytesReceived.ToString());
                        double totalBytes            = double.Parse(e.TotalBytesToReceive.ToString());
                        double percentage            = bytesIn / totalBytes * 100;
                        CurrentProgressLabel.Content = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
                        CurrentProgressBar.Value     = int.Parse(Math.Truncate(percentage).ToString());
                    }));
                };
                #endregion

                #region Update this client

                string CurrentMD5 = GetMd5();
                LogTextBox("MD5: " + CurrentMD5);
                string VersionString = "";
                try
                {
                    VersionString = client.DownloadString(new Uri("http://legendaryclient.com/update.html"));
                }
                catch
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Could not retrieve update files!";
                        Client.Log("Couldn't get update files for LegendaryClient");
                    }));
                    return;
                }

                string[] VersionSplit = VersionString.Split('|');

                LogTextBox("Update data: " + VersionSplit[0] + "|" + VersionSplit[1]);
                Client.Log("Update data: " + VersionSplit[0] + "|" + VersionSplit[1]);

#if !DEBUG //Dont patch client while in DEBUG
                if (VersionSplit.Length == 3)
                {
                    string[] versionArray = VersionString.Split('|');
                    if (VersionSplit[0] != CurrentMD5)
                    {
                        LogTextBox("LegendaryClient needs to be updated");

                        /*Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                         * {
                         *  CurrentStatusLabel.Content = "Downloading latest LegendaryClient...";
                         * }));
                         *
                         * client.DownloadFile(versionArray[2], "COL.ZIP");
                         * Directory.CreateDirectory("Patch");
                         * System.IO.Compression.ZipFile.ExtractToDirectory("COL.ZIP", "Patch");
                         * File.Delete("COL.ZIP");
                         * System.Diagnostics.Process.Start("Patcher.exe");
                         * Environment.Exit(0);*/
                    }
                }
#endif
                LogTextBox("LegendaryClient is up to date");
                Client.Log("LC Patched");

                #endregion LegendaryClient

                #region ProgressBar 20%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "20%";
                    TotalProgessBar.Value      = 20;
                }));
                #endregion

                #region Get DDragon data

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                if (!Directory.Exists("Assets"))
                {
                    Directory.CreateDirectory("Assets");
                }
                if (!File.Exists(Path.Combine("Assets", "VERSION_DDRagon")))
                {
                    var VersionLOL = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionLOL.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);
                    VersionLOL.Close();
                }

                RiotPatcher patcher       = new RiotPatcher();
                string DDragonDownloadURL = patcher.GetDragon();
                if (!DDragonDownloadURL.StartsWith("http:"))
                {
                    DDragonDownloadURL = "http:" + DDragonDownloadURL;
                }
                LogTextBox("DataDragon Version: " + patcher.DDragonVersion);
                string DDragonVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                LogTextBox("Current DataDragon Version: " + DDragonVersion);
                Client.Log("DD: " + patcher.DDragonVersion + "|" + DDragonVersion);

                if (patcher.DDragonVersion != DDragonVersion)
                {
                    if (!Directory.Exists(Path.Combine("Assets", "temp")))
                    {
                        Directory.CreateDirectory(Path.Combine("Assets", "temp"));
                    }

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Downloading DataDragon";
                    }));

                    client.DownloadFile(DDragonDownloadURL, Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Extracting DataDragon";
                    }));

                    Stream inStream = File.OpenRead(Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));
                    using (GZipInputStream gzipStream = new GZipInputStream(inStream))
                    {
                        TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                        tarArchive.ExtractContents(Path.Combine("Assets", "temp"));
                        tarArchive.CloseArchive();
                    }
                    inStream.Close();

                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "data"), Path.Combine("Assets", "data"));
                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "img"), Path.Combine("Assets"));
                    Directory.Delete(Path.Combine("Assets", "temp"), true);

                    var VersionDDragon = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionDDragon.Write(encoding.GetBytes(patcher.DDragonVersion), 0, encoding.GetBytes(patcher.DDragonVersion).Length);
                    VersionDDragon.Close();
                }

                #endregion DDragon

                #region ProgressBar 50%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "50%";
                    TotalProgessBar.Value      = 50;
                }));
                #endregion

                #region Update lol_air_client

                if (!File.Exists(Path.Combine("Assets", "VERSION_AIR")))
                {
                    var VersionAIR = File.Create(Path.Combine("Assets", "VERSION_AIR"));
                    VersionAIR.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionAIR.Close();
                }

                string LatestAIR = patcher.GetLatestAir();
                LogTextBox("Air Assets Version: " + LatestAIR);
                string AirVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                LogTextBox("Current Air Assets Version: " + AirVersion);
                bool RetrieveCurrentInstallation = false;
                string AirLocation = "";
                Client.Log("AIR: " + LatestAIR + "|" + AirVersion);

                if (AirVersion == "0.0.0.0")
                {
                    LogTextBox("Checking for existing League of Legends Installation");
                    AirLocation = Path.Combine("League of Legends", "RADS", "projects", "lol_air_client", "releases");
                    if (Directory.Exists(AirLocation))
                    {
                        RetrieveCurrentInstallation = true;
                    }
                    else if (Directory.Exists(Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", AirLocation)))
                    {
                        RetrieveCurrentInstallation = true;
                        AirLocation = Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", AirLocation);
                    }
                    else
                    {
                        LogTextBox("Unable to find existing League of Legends. Copy your League of Legends folder into + "
                                   + Client.ExecutingDirectory
                                   + " to make the patching process quicker");
                    }

                    if (RetrieveCurrentInstallation)
                    {
                        Client.Log("Got previous installation: " + AirLocation);
                        LogTextBox("Getting Air Assets from " + AirLocation);
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            CurrentProgressLabel.Content = "Copying Air Assets";
                        }));
                        AirVersion = patcher.GetCurrentAirInstall(AirLocation);
                        LogTextBox("Retrieved currently installed Air Assets");
                        LogTextBox("Current Air Assets Version: " + AirVersion);
                    }
                }

                if (AirVersion != LatestAIR)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Retrieving Air Assets";
                    }));
                    AirLocation = Path.Combine("League of Legends", "RADS", "projects", "lol_air_client", "releases");
                    if (Directory.Exists(AirLocation))
                    {
                        AirVersion = patcher.GetCurrentAirInstall(AirLocation);
                        LogTextBox("Retrieved currently installed Air Assets");
                        LogTextBox("Current Air Assets Version: " + AirVersion);
                    }
                }

                #endregion lol_air_client

                #region ProgressBar 70%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "70%";
                    TotalProgessBar.Value      = 70;
                }));
                #endregion

                #region Update lol_game_client

                if (!Directory.Exists("RADS"))
                {
                    Directory.CreateDirectory("RADS");
                }

                if (!File.Exists(Path.Combine("RADS", "VERSION_LOL")))
                {
                    var VersionGAME = File.Create(Path.Combine("RADS", "VERSION_LOL"));
                    VersionGAME.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionGAME.Close();
                }

                string LatestGame = patcher.GetLatestGame();
                LogTextBox("League of Legends Version: " + LatestGame);
                string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                LogTextBox("Current League of Legends Version: " + GameVersion);
                RetrieveCurrentInstallation = false;
                string GameLocation         = "";

                if (GameVersion == "0.0.0.0")
                {
                    LogTextBox("Checking for existing League of Legends Installation");
                    GameLocation = Path.Combine("League of Legends", "RADS");
                    if (Directory.Exists(GameLocation))
                    {
                        RetrieveCurrentInstallation = true;
                    }
                    else if (Directory.Exists(Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", GameLocation)))
                    {
                        RetrieveCurrentInstallation = true;
                        GameLocation = Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", GameLocation);
                    }
                    else
                    {
                        LogTextBox("Unable to find existing League of Legends. Copy your League of Legends folder into + "
                                   + Client.ExecutingDirectory
                                   + " to make the patching process quicker");
                    }

                    if (RetrieveCurrentInstallation)
                    {
                        LogTextBox("Getting League Of Legends from " + GameLocation);
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            CurrentProgressLabel.Content = "Copying League of Legends";
                        }));
                        GameVersion = patcher.GetCurrentGameInstall(GameLocation);
                        LogTextBox("Retrieved currently installed League of Legends");
                        LogTextBox("Current League of Legends Version: " + GameVersion);
                    }
                }

                if (GameVersion != LatestGame)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Retrieving League of Legends";
                    }));
                    GameLocation = Path.Combine("League of Legends", "RADS");
                    if (Directory.Exists(GameLocation))
                    {
                        GameVersion = patcher.GetCurrentGameInstall(GameLocation);
                        LogTextBox("Retrieved currently installed League of Legends");
                        LogTextBox("Current League of Legends Version: " + GameVersion);
                    }
                }

                #endregion lol_game_client

                #region ProgressBar 90%
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "90%";
                    TotalProgessBar.Value      = 90;
                }));
                #endregion

                FinishPatching();
            });
            bgThread.IsBackground = true;
            bgThread.Start();
        }
Example #6
0
        public static void CreateArchive(ProgressMonitor mon, string folder, string targetFile)
        {
            string tf = Path.GetFileNameWithoutExtension(targetFile);

            if (tf.EndsWith(".tar"))
            {
                tf = Path.GetFileNameWithoutExtension(tf);
            }

            if (File.Exists(targetFile))
            {
                File.Delete(targetFile);
            }

            using (Stream os = File.Create(targetFile)) {
                Stream outStream = os;
                // Create the zip file
                switch (GetArchiveExtension(targetFile))
                {
                case ".tar.gz":
                    outStream = new GZipOutputStream(outStream);
                    goto case ".tar";

                case ".tar.bz2":
                    outStream = new BZip2OutputStream(outStream, 9);
                    goto case ".tar";

                case ".tar":
                    TarArchive archive = TarArchive.CreateOutputTarArchive(outStream);
                    archive.SetAsciiTranslation(false);
                    archive.RootPath              = folder;
                    archive.ProgressMessageEvent += delegate(TarArchive ac, TarEntry e, string message) {
                        if (message != null)
                        {
                            mon.Log.WriteLine(message);
                        }
                    };

                    foreach (FilePath f in GetFilesRec(new DirectoryInfo(folder)))
                    {
                        TarEntry entry = TarEntry.CreateEntryFromFile(f);
                        entry.Name = f.ToRelative(folder);
                        if (!Platform.IsWindows)
                        {
                            UnixFileInfo fi = new UnixFileInfo(f);
                            entry.TarHeader.Mode = (int)fi.Protection;
                        }
                        else
                        {
                            entry.Name = entry.Name.Replace('\\', '/');
                            FilePermissions p = FilePermissions.S_IFREG | FilePermissions.S_IROTH | FilePermissions.S_IRGRP | FilePermissions.S_IRUSR;
                            if (!new FileInfo(f).IsReadOnly)
                            {
                                p |= FilePermissions.S_IWUSR;
                            }
                            entry.TarHeader.Mode = (int)p;
                        }
                        archive.WriteEntry(entry, false);
                    }

                    // HACK: GNU tar expects to find a double zero record at the end of the archive. TarArchive only emits one.
                    // This hack generates the second zero block.
                    FieldInfo tarOutField = typeof(TarArchive).GetField("tarOut", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (tarOutField != null)
                    {
                        TarOutputStream tarOut = (TarOutputStream)tarOutField.GetValue(archive);
                        tarOut.Finish();
                    }

                    archive.CloseArchive();
                    break;

                case ".zip":
                    ZipOutputStream zs = new ZipOutputStream(outStream);
                    zs.SetLevel(5);

                    byte[] buffer = new byte [8092];
                    foreach (FilePath f in GetFilesRec(new DirectoryInfo(folder)))
                    {
                        string name = f.ToRelative(folder);
                        if (Platform.IsWindows)
                        {
                            name = name.Replace('\\', '/');
                        }
                        ZipEntry infoEntry = new ZipEntry(name);
                        zs.PutNextEntry(infoEntry);
                        using (Stream s = File.OpenRead(f)) {
                            int nr;
                            while ((nr = s.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                zs.Write(buffer, 0, nr);
                            }
                        }
                        zs.CloseEntry();
                    }
                    zs.Finish();
                    zs.Close();
                    break;

                default:
                    mon.Log.WriteLine("Unsupported file format: " + Path.GetFileName(targetFile));
                    return;
                }
            }
        }
Example #7
0
        /// <summary>
        /// Creates the tar file.
        /// </summary>
        protected override void ExecuteTask()
        {
            TarArchive archive   = null;
            Stream     outstream = null;

            Log(Level.Info, "Tarring {0} files to '{1}'.",
                TarFileSets.FileCount, DestFile.FullName);

            try {
                outstream = File.Create(DestFile.FullName);

                // wrap outputstream with corresponding compression method
                switch (CompressionMethod)
                {
                case TarCompressionMethod.GZip:
                    outstream = new GZipOutputStream(outstream);
                    break;

                case TarCompressionMethod.BZip2:
                    outstream = new BZip2OutputStream(outstream);
                    break;
                }

                // create tar archive
                archive = TarArchive.CreateOutputTarArchive(outstream,
                                                            TarBuffer.DefaultBlockFactor);

                // do not use convert line endings of text files to \n, as this
                // converts all content to ASCII
                archive.SetAsciiTranslation(false);

                // process all filesets
                foreach (TarFileSet fileset in TarFileSets)
                {
                    string basePath = fileset.BaseDirectory.FullName;

                    if (Path.GetPathRoot(basePath) != basePath)
                    {
                        basePath = Path.GetDirectoryName(basePath + Path.DirectorySeparatorChar);
                    }

                    // add files to tar
                    foreach (string file in fileset.FileNames)
                    {
                        // ensure file exists (in case "asis" was used)
                        if (!File.Exists(file))
                        {
                            throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                                   "File '{0}' does not exist.", file), Location);
                        }

                        // the filename of the tar entry
                        string entryFileName;

                        // the directory of the tar entry
                        string entryDirName = string.Empty;

                        // determine name of the tar entry
                        if (file.StartsWith(basePath))
                        {
                            entryFileName = file.Substring(basePath.Length);
                            if (entryFileName.Length > 0 && entryFileName[0] == Path.DirectorySeparatorChar)
                            {
                                entryFileName = entryFileName.Substring(1);
                            }

                            // get directory part of entry
                            entryDirName = Path.GetDirectoryName(entryFileName);

                            // ensure directory separators are understood on linux
                            if (Path.DirectorySeparatorChar == '\\')
                            {
                                entryDirName = entryDirName.Replace(@"\", "/");
                            }

                            // get filename part of entry
                            entryFileName = Path.GetFileName(entryFileName);
                        }
                        else
                        {
                            entryFileName = Path.GetFileName(file);
                        }

                        // add prefix if specified
                        if (fileset.Prefix != null)
                        {
                            entryDirName = fileset.Prefix + entryDirName;
                        }

                        // ensure directory has trailing slash
                        if (entryDirName.Length != 0)
                        {
                            if (!entryDirName.EndsWith("/"))
                            {
                                entryDirName += '/';
                            }

                            // create directory entry in archive
                            CreateDirectoryEntry(archive, entryDirName, fileset);
                        }

                        TarEntry entry = TarEntry.CreateEntryFromFile(file);
                        entry.Name           = entryDirName + entryFileName;
                        entry.GroupId        = fileset.Gid;
                        entry.GroupName      = fileset.GroupName;
                        entry.UserId         = fileset.Uid;
                        entry.UserName       = fileset.UserName;
                        entry.TarHeader.Mode = fileset.FileMode;

                        // write file to tar file
                        archive.WriteEntry(entry, true);
                    }

                    // add (possibly empty) directories to zip
                    if (IncludeEmptyDirs)
                    {
                        // add (possibly empty) directories to tar
                        foreach (string directory in fileset.DirectoryNames)
                        {
                            // skip directories that are not located beneath the base
                            // directory
                            if (!directory.StartsWith(basePath) || directory.Length <= basePath.Length)
                            {
                                continue;
                            }

                            // determine tar entry name
                            string entryName = directory.Substring(basePath.Length + 1);

                            // add prefix if specified
                            if (fileset.Prefix != null)
                            {
                                entryName = fileset.Prefix + entryName;
                            }

                            // ensure directory separators are understood on linux
                            if (Path.DirectorySeparatorChar == '\\')
                            {
                                entryName = entryName.Replace(@"\", "/");
                            }

                            if (!entryName.EndsWith("/"))
                            {
                                // trailing directory signals to #ziplib that we're
                                // dealing with directory entry
                                entryName += "/";
                            }

                            // create directory entry in archive
                            CreateDirectoryEntry(archive, entryName, fileset);
                        }
                    }
                }

                // close the tar archive
                archive.CloseArchive();
            } catch (Exception ex) {
                // close the tar output stream
                if (outstream != null)
                {
                    outstream.Close();
                }

                // close the tar archive
                if (archive != null)
                {
                    archive.CloseArchive();
                }

                // delete the (possibly corrupt) tar file
                if (DestFile.Exists)
                {
                    DestFile.Delete();
                }

                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Tar file '{0}' could not be created.", DestFile.FullName),
                                         Location, ex);
            }
        }
        private void StartPatcher()
        {
            Thread bgThead = new Thread(() =>
            {
                LogTextBox("Starting Patcher");

                WebClient client = new WebClient();
                client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                client.DownloadFileCompleted   += new AsyncCompletedEventHandler(client_DownloadDDragon);
                client.DownloadProgressChanged += (o, e) =>
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        double bytesIn               = double.Parse(e.BytesReceived.ToString());
                        double totalBytes            = double.Parse(e.TotalBytesToReceive.ToString());
                        double percentage            = bytesIn / totalBytes * 100;
                        CurrentProgressLabel.Content = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
                        CurrentProgressBar.Value     = int.Parse(Math.Truncate(percentage).ToString());
                    }));
                };

                #region LegendaryClient

                string CurrentMD5 = GetMd5();
                LogTextBox("MD5: " + CurrentMD5);


                UpdateData legendaryupdatedata = new UpdateData();
                var version = LegendaryClientPatcher.GetLatestLCVersion();
                LogTextBox("Most Up to date LegendaryClient Version: " + version);
                string versionAsString = version;

                if (version != Client.LegendaryClientVersion)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        MessageOverlay overlay              = new MessageOverlay();
                        overlay.MessageTextBox.Text         = "An update is available LegendaryClient";
                        overlay.MessageTitle.Content        = "Update Notification";
                        overlay.AcceptButton.Content        = "Update LegendaryClient";
                        overlay.AcceptButton.Click         += update;
                        overlay.MessageTextBox.TextChanged += Text_Changed;
                        Client.OverlayContainer.Content     = overlay.Content;
                        //Client.OverlayContainer.Visibility = Visibility.Visible;

                        CurrentProgressLabel.Content = "LegendaryClient Is Out of Date!";
                    }));
                    LogTextBox("LegendaryClient Is Out of Date!");

                    //return;
                }
                else if (Client.LegendaryClientVersion == version)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "LegendaryClient Is Up To Date!";
                    }));
                    LogTextBox("LegendaryClient Is Up To Date!");
                }
                else if (version == null)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Could not check LegendaryClient Version!";
                    }));
                    LogTextBox("Could not check LegendaryClient Version!");
                    return;
                }

                #endregion LegendaryClient

                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "20%";
                    TotalProgessBar.Value      = 20;
                }));

                #region DDragon

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                if (!Directory.Exists("Assets"))
                {
                    Directory.CreateDirectory("Assets");
                }
                if (!File.Exists(Path.Combine("Assets", "VERSION_DDRagon")))
                {
                    var VersionLOL = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionLOL.Write(encoding.GetBytes("0.0.0"), 0, encoding.GetBytes("0.0.0").Length);

                    VersionLOL.Close();
                }


                RiotPatcher patcher       = new RiotPatcher();
                string DDragonDownloadURL = patcher.GetDragon();
                LogTextBox("DataDragon Version: " + patcher.DDragonVersion);
                string DDragonVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_DDragon"));
                LogTextBox("Current DataDragon Version: " + DDragonVersion);

                Client.Version = DDragonVersion;
                Client.Log("DDragon Version (LOL Version) = " + DDragonVersion);

                LogTextBox("Client Version: " + Client.Version);

                if (patcher.DDragonVersion != DDragonVersion)
                {
                    if (!Directory.Exists(Path.Combine("Assets", "temp")))
                    {
                        Directory.CreateDirectory(Path.Combine("Assets", "temp"));
                    }

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Downloading DataDragon";
                    }));

                    client.DownloadFile(DDragonDownloadURL, Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Extracting DataDragon";
                    }));

                    Stream inStream = File.OpenRead(Path.Combine("Assets", "dragontail-" + patcher.DDragonVersion + ".tgz"));

                    using (GZipInputStream gzipStream = new GZipInputStream(inStream))
                    {
                        TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
                        tarArchive.ExtractContents(Path.Combine("Assets", "temp"));
                        tarArchive.CloseArchive();
                    }
                    inStream.Close();

                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "data"), Path.Combine("Assets", "data"));
                    Copy(Path.Combine("Assets", "temp", patcher.DDragonVersion, "img"), Path.Combine("Assets"));
                    DeleteDirectoryRecursive(Path.Combine("Assets", "temp"));

                    var VersionDDragon = File.Create(Path.Combine("Assets", "VERSION_DDRagon"));
                    VersionDDragon.Write(encoding.GetBytes(patcher.DDragonVersion), 0, encoding.GetBytes(patcher.DDragonVersion).Length);

                    Client.Version = DDragonVersion;
                    VersionDDragon.Close();
                }

                #endregion DDragon

                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TotalProgressLabel.Content = "40%";
                    TotalProgessBar.Value      = 40;
                }));

                // Try get LoL path from registry

                //A string that looks like C:\Riot Games\League of Legends\
                string lolRootPath = GetLolRootPath();

                #region lol_air_client

                if (!File.Exists(Path.Combine("Assets", "VERSION_AIR")))
                {
                    var VersionAIR = File.Create(Path.Combine("Assets", "VERSION_AIR"));
                    VersionAIR.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionAIR.Close();
                }

                string LatestAIR = patcher.GetLatestAir();
                LogTextBox("Air Assets Version: " + LatestAIR);
                string AirVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                LogTextBox("Current Air Assets Version: " + AirVersion);
                bool RetrieveCurrentInstallation = false;
                WebClient UpdateClient           = new WebClient();
                string Release       = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting");
                string LatestVersion = Release.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];

                if (AirVersion != LatestVersion)
                {
                    //Download Air Assists from riot
                    string Package = UpdateClient.DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion + "/packages/files/packagemanifest");
                    GetAllPngs(Package);
                    if (File.Exists(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite")))
                    {
                        File.Delete(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
                    }
                    UpdateClient.DownloadFile(new Uri("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/" + LatestVersion + "/files/assets/data/gameStats/gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));

                    if (File.Exists(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR")))
                    {
                        File.Delete(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                    }
                    var file = File.Create(System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "VERSION_AIR"));
                    file.Write(encoding.GetBytes(LatestVersion), 0, encoding.GetBytes(LatestVersion).Length);
                    file.Close();
                }

                if (AirVersion != LatestAIR)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        SkipPatchButton.IsEnabled    = true;
                        CurrentProgressLabel.Content = "Retrieving Air Assets";
                    }));
                }

                #endregion lol_air_client


                //string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                #region lol_game_client
                LogTextBox("Trying to detect League of Legends GameClient");
                LogTextBox("League of Legends is located at: " + lolRootPath);
                //RADS\solutions\lol_game_client_sln\releases
                var GameLocation = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases");

                string LolVersion2   = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_game_client/releases/releaselisting_NA");
                string LolVersion    = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/solutions/lol_game_client_sln/releases/releaselisting_NA");
                string GameClientSln = LolVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                string GameClient    = LolVersion2.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                LogTextBox("Latest League of Legends GameClient: " + GameClientSln);
                LogTextBox("Checking if League of Legends is Up-To-Date");

                string LolLauncherVersion = new WebClient().DownloadString("http://l3cdn.riotgames.com/releases/live/projects/lol_air_client/releases/releaselisting_NA");
                string LauncherVersion    = LolLauncherVersion.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[0];
                if (Directory.Exists(Path.Combine(GameLocation, GameClientSln)))
                {
                    LogTextBox("League of Legends is Up-To-Date");
                    //Client.LaunchGameLocation = Path.Combine(Client.GameLocation, GameClientSln);
                    //C:\Riot Games\League of Legends\RADS\projects\lol_game_client\releases\0.0.0.243\deploy
                    Client.LOLCLIENTVERSION = LolVersion2;
                    //C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.50\deploy
                    Client.Location = Path.Combine(lolRootPath, "RADS", "solutions", "lol_game_client_sln", "releases", GameClientSln, "deploy");
                    //C:\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\0.0.1.104
                    Client.LoLLauncherLocation = Path.Combine(lolRootPath, "RADS", "projects", "lol_air_client", "releases", LauncherVersion, "deploy");
                    Client.RootLocation        = lolRootPath;
                }
                else
                {
                    LogTextBox("League of Legends is not Up-To-Date. Please Update League Of Legends");
                    return;
                }


                if (!Directory.Exists("RADS"))
                {
                    Directory.CreateDirectory("RADS");
                }

                if (!File.Exists(Path.Combine("RADS", "VERSION_LOL")))
                {
                    var VersionGAME = File.Create(Path.Combine("RADS", "VERSION_LOL"));
                    VersionGAME.Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
                    VersionGAME.Close();
                }

                string LatestGame = patcher.GetLatestGame();
                LogTextBox("League Of Legends Version: " + LatestGame);
                string GameVersion = File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "RADS", "VERSION_LOL"));
                LogTextBox("Current League of Legends Version: " + GameVersion);
                RetrieveCurrentInstallation = false;
                string NGameLocation        = "";

                if (GameVersion != GameClient)
                {
                    LogTextBox("Checking for existing League of Legends Installation");
                    NGameLocation = Path.Combine("League of Legends", "RADS");
                    if (Directory.Exists(NGameLocation))
                    {
                        RetrieveCurrentInstallation = true;
                    }
                    else if (Directory.Exists(Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", NGameLocation)))
                    {
                        RetrieveCurrentInstallation = true;
                        NGameLocation = Path.Combine(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", NGameLocation);
                    }
                    else
                    {
                        LogTextBox("Unable to find existing League of Legends. Copy your League of Legends folder into + "
                                   + Client.ExecutingDirectory
                                   + " to make the patching process quicker");
                    }

                    if (RetrieveCurrentInstallation)
                    {
                        LogTextBox("Getting League Of Legends from " + NGameLocation);
                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                        {
                            CurrentProgressLabel.Content = "Copying League of Legends";
                        }));
                        LogTextBox("Retrieved currently installed League of Legends");
                        LogTextBox("Current League of Legends Version: " + NGameLocation);
                    }
                }

                if (GameVersion != LatestGame)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        CurrentProgressLabel.Content = "Retrieving League of Legends";
                    }));
                }
                #endregion lol_game_client



                FinishPatching(LatestVersion);
            });

            bgThead.Start();
        }
Example #9
0
    /// <summary>
    /// This is the "real" main. The class main() instantiates a tar object
    /// for the application and then calls this method. Process the arguments
    /// and perform the requested operation.
    /// </summary>
    public void InstanceMain(string[] argv)
    {
        TarArchive archive = null;

        int argIdx = this.ProcessArguments(argv);

        if (this.archiveName != null && !this.archiveName.Equals("-"))
        {
            if (operation == Operation.Create)
            {
                if (!Directory.Exists(Path.GetDirectoryName(archiveName)))
                {
                    Console.Error.WriteLine("Directory for archive doesnt exist");
                    return;
                }
            }
            else
            {
                if (File.Exists(this.archiveName) == false)
                {
                    Console.Error.WriteLine("File does not exist " + this.archiveName);
                    return;
                }
            }
        }

        if (operation == Operation.Create)                                     // WRITING
        {
            Stream outStream = Console.OpenStandardOutput();

            if (this.archiveName != null && !this.archiveName.Equals("-"))
            {
                outStream = File.Create(archiveName);
            }

            if (outStream != null)
            {
                switch (this.compression)
                {
                case Compression.Compress:
                    outStream = new DeflaterOutputStream(outStream);
                    break;

                case Compression.Gzip:
                    outStream = new GZipOutputStream(outStream);
                    break;

                case Compression.Bzip2:
                    outStream = new BZip2OutputStream(outStream, 9);
                    break;
                }
                archive = TarArchive.CreateOutputTarArchive(outStream, this.blockingFactor);
            }
        }
        else                                                                            // EXTRACTING OR LISTING
        {
            Stream inStream = Console.OpenStandardInput();

            if (this.archiveName != null && !this.archiveName.Equals("-"))
            {
                inStream = File.OpenRead(archiveName);
            }

            if (inStream != null)
            {
                switch (this.compression)
                {
                case Compression.Compress:
                    inStream = new InflaterInputStream(inStream);
                    break;

                case Compression.Gzip:
                    inStream = new GZipInputStream(inStream);
                    break;

                case Compression.Bzip2:
                    inStream = new BZip2InputStream(inStream);
                    break;
                }
                archive = TarArchive.CreateInputTarArchive(inStream, this.blockingFactor);
            }
        }

        if (archive != null)                                                    // SET ARCHIVE OPTIONS
        {
            archive.SetKeepOldFiles(this.keepOldFiles);
            archive.SetAsciiTranslation(this.asciiTranslate);

            archive.SetUserInfo(this.userId, this.userName, this.groupId, this.groupName);
        }

        if (archive == null)
        {
            Console.Error.WriteLine("no processing due to errors");
        }
        else if (operation == Operation.Create)                                    // WRITING
        {
            if (verbose)
            {
                archive.ProgressMessageEvent += new ProgressMessageHandler(ShowTarProgressMessage);
            }

            for ( ; argIdx < argv.Length; ++argIdx)
            {
                string[] fileNames = GetFilesForSpec(argv[argIdx]);
                if (fileNames.Length > 0)
                {
                    foreach (string name in fileNames)
                    {
                        TarEntry entry = TarEntry.CreateEntryFromFile(name);
                        archive.WriteEntry(entry, true);
                    }
                }
                else
                {
                    Console.Error.Write("No files for " + argv[argIdx]);
                }
            }
        }
        else if (operation == Operation.List)                               // LISTING
        {
            archive.ProgressMessageEvent += new ProgressMessageHandler(ShowTarProgressMessage);
            archive.ListContents();
        }
        else                                                                // EXTRACTING
        {
            string userDir = Environment.CurrentDirectory;
            if (verbose)
            {
                archive.ProgressMessageEvent += new ProgressMessageHandler(ShowTarProgressMessage);
            }

            if (userDir != null)
            {
                archive.ExtractContents(userDir);
            }
        }

        if (archive != null)                                             // CLOSE ARCHIVE
        {
            archive.CloseArchive();
        }
    }