Example #1
0
        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;
                    }

                    WriteAllTextWithCorrectPermissions(contents.Trim(), destinationFilePath);
                    // File.WriteAllText(destinationFilePath, contents.Trim());
                }
            }
            else
            {
                if (File.Exists(destinationFilePath))
                {
                    new FileInfo(destinationFilePath).IsReadOnly = false;
                }

                WriteAllTextWithCorrectPermissions(contents.Trim(), destinationFilePath);
                // File.WriteAllText(destinationFilePath, contents.Trim());
            }
        }
Example #2
0
        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);
            }
        }