Example #1
0
        /// <summary>
        /// Applies patch to npm package.
        /// </summary>
        private void ApplyPatch()
        {
            foreach (KeyValuePair <string, string> pair in PatchMap)
            {
                FileInfo src  = new FileInfo(string.Format("{0}{1}patch\\{2}", ProjectPath, PackageName, pair.Key));
                FileInfo dest = new FileInfo(string.Format("{0}{1}", ProjectPath, pair.Value));

                if (!File.Exists(src.FullName))
                {
                    NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Error. {0} does not exist",
                                                         src.FullName), NpmOutputPane);
                    continue;
                }

                try
                {
                    if (!Directory.Exists(dest.DirectoryName))
                    {
                        Directory.CreateDirectory(dest.DirectoryName);
                    }
                    NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Copying {0} to {1}",
                                                         src.FullName, dest.FullName), NpmOutputPane);
                    File.Copy(src.FullName, dest.FullName, true);
                }
                catch (Exception ex)
                {
                    NpmHandler.PrintOutput(ex.Message, NpmOutputPane);
                }
            }
            NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "{0} UWP patch applied!",
                                                 PackageName), NpmOutputPane);
        }
Example #2
0
        /// <summary>
        /// Initiates patch download.
        /// </summary>
        private void DownloadPatch()
        {
            WebClient client = new WebClient();

            ZipFilePath = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", ProjectPath, PackageName, "patch.zip");

            NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Downloading {0} UWP patch from {1}",
                                                 PackageName, PatchUri.ToString()), NpmOutputPane);
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadPatchCompleted);
            client.DownloadFileAsync(PatchUri, ZipFilePath);
        }
Example #3
0
        /// <summary>
        /// Extracts and applies patch after download completes.
        /// </summary>
        private void DownloadPatchCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Download failed: {0}",
                                                     e.Error.Message), NpmOutputPane);
                return;
            }

            NpmHandler.PrintOutput("Download complete.", NpmOutputPane);
            ExtractPatch();
            ApplyPatch();
        }
Example #4
0
        /// <summary>
        /// Extracts patch zip file.
        /// </summary>
        private void ExtractPatch()
        {
            NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Extracting {0} UWP patch.",
                                                 PackageName), NpmOutputPane);

            string ZipFileExtractPath = string.Format(CultureInfo.CurrentCulture, "{0}{1}patch", ProjectPath, PackageName);

            try
            {
                // Clean existing extracted path
                if (Directory.Exists(ZipFileExtractPath))
                {
                    Directory.Delete(ZipFileExtractPath, true);
                }
                ZipFile.ExtractToDirectory(ZipFilePath, ZipFileExtractPath);
            }
            catch (Exception ex)
            {
                NpmHandler.PrintOutput(ex.Message, NpmOutputPane);
                return;
            }
            NpmHandler.PrintOutput("Extraction complete.", NpmOutputPane);
        }