private static Uri DownloadFile(string ramlSource, string destinationFilePath, bool confirmOvewrite = false)
        {
            Uri uri;

            if (!Uri.TryCreate(ramlSource, UriKind.Absolute, out uri))
            {
                throw new UriFormatException("Invalid URL: " + ramlSource);
            }

            var contents = Downloader.GetContents(uri);

            if (File.Exists(destinationFilePath) && confirmOvewrite)
            {
                var dialogResult = InstallerServices.ShowConfirmationDialog(Path.GetFileName(destinationFilePath));
                if (dialogResult == MessageBoxResult.Yes)
                {
                    if (File.Exists(destinationFilePath))
                    {
                        new FileInfo(destinationFilePath).IsReadOnly = false;
                    }
                    File.WriteAllText(destinationFilePath, contents);
                }
            }
            else
            {
                if (File.Exists(destinationFilePath))
                {
                    new FileInfo(destinationFilePath).IsReadOnly = false;
                }
                File.WriteAllText(destinationFilePath, contents);
            }

            return(uri);
        }
        private void ManageLocalFile(string path, string relativePath, bool confirmOvewrite, string includeSource,
                                     string destinationFilePath)
        {
            var fullPathIncludeSource = includeSource;

            // if relative does not exist, try with full path
            if (!File.Exists(includeSource))
            {
                fullPathIncludeSource = ResolveFullPath(path, relativePath, includeSource);
                if (!relativePaths.ContainsKey(destinationFilePath))
                {
                    relativePaths.Add(destinationFilePath, Path.GetDirectoryName(fullPathIncludeSource));
                }
            }

            if (destinationFilePath == fullPathIncludeSource)
            {
                return;
            }

            // copy file to dest folder
            if (File.Exists(destinationFilePath) && confirmOvewrite)
            {
                var dialogResult = InstallerServices.ShowConfirmationDialog(Path.GetFileName(destinationFilePath));
                if (dialogResult == MessageBoxResult.Yes)
                {
                    if (File.Exists(destinationFilePath))
                    {
                        new FileInfo(destinationFilePath).IsReadOnly = false;
                    }

                    File.Copy(fullPathIncludeSource, destinationFilePath, true);
                }
            }
            else
            {
                if (File.Exists(destinationFilePath))
                {
                    new FileInfo(destinationFilePath).IsReadOnly = false;
                }

                File.Copy(fullPathIncludeSource, destinationFilePath, true);
            }
        }
 private static void WriteFile(string destinationFilePath, bool confirmOvewrite, string contents)
 {
     if (File.Exists(destinationFilePath) && confirmOvewrite)
     {
         var dialogResult = InstallerServices.ShowConfirmationDialog(Path.GetFileName(destinationFilePath));
         if (dialogResult == MessageBoxResult.Yes)
         {
             if (File.Exists(destinationFilePath))
             {
                 new FileInfo(destinationFilePath).IsReadOnly = false;
             }
             File.WriteAllText(destinationFilePath, contents.Trim());
         }
     }
     else
     {
         if (File.Exists(destinationFilePath))
         {
             new FileInfo(destinationFilePath).IsReadOnly = false;
         }
         File.WriteAllText(destinationFilePath, contents.Trim());
     }
 }
        private void Manage(IList <string> lines, string destinationFolder, ICollection <string> includedFiles, string path, bool confirmOvewrite)
        {
            for (var i = 0; i < lines.Count; i++)
            {
                var line = lines[i];
                if (!line.Contains(IncludeDirective))
                {
                    continue;
                }

                var indexOfInclude = line.IndexOf(IncludeDirective, System.StringComparison.Ordinal);
                var includeSource  = line.Substring(indexOfInclude + IncludeDirective.Length).Trim(IncludeDirectiveTrimChars);

                var destinationFilePath = GetDestinationFilePath(destinationFolder, includeSource);

                if (IsWebSource(path, includeSource))
                {
                    var fullPathIncludeSource = GetFullWebSource(path, includeSource);
                    DownloadFile(fullPathIncludeSource, destinationFilePath);
                }
                else
                {
                    var fullPathIncludeSource = includeSource;
                    // if relative does not exist, try with full path
                    if (!File.Exists(includeSource))
                    {
                        fullPathIncludeSource = Path.Combine(path, includeSource);
                    }


                    // copy file to dest folder
                    if (File.Exists(destinationFilePath) && confirmOvewrite)
                    {
                        var dialogResult = InstallerServices.ShowConfirmationDialog(Path.GetFileName(destinationFilePath));
                        if (dialogResult == MessageBoxResult.Yes)
                        {
                            if (File.Exists(destinationFilePath))
                            {
                                new FileInfo(destinationFilePath).IsReadOnly = false;
                            }

                            File.Copy(fullPathIncludeSource, destinationFilePath, true);
                        }
                    }
                    else
                    {
                        if (File.Exists(destinationFilePath))
                        {
                            new FileInfo(destinationFilePath).IsReadOnly = false;
                        }

                        File.Copy(fullPathIncludeSource, destinationFilePath, true);
                    }
                }

                // replace old include for new include
                lines[i] = lines[i].Replace(includeSource, GetPathWithoutDriveLetter(destinationFilePath));

                includedFiles.Add(destinationFilePath);

                // parse include for other includes
                var nestedFileLines = File.ReadAllLines(destinationFilePath);
                Manage(nestedFileLines, destinationFolder, includedFiles, path, confirmOvewrite);
            }
        }