Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6693 Alert user for duplicate files when publishing package #15225

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3983,6 +3983,12 @@ To make this file into a new template, save it to a different folder, then move
<data name="MessagePackOlderDynamoLink" xml:space="preserve">
<value>#Learn more=https://primer2.dynamobim.org/1_developer_primer_intro/3_developing_for_dynamo/updating-your-packages-and-dynamo-libraries-for-dynamo-3x-net8</value>
</data>
<data name="DuplicateFilesInPublishWarningMessage" xml:space="preserve">
<value>Files with same name will be overwritten in the final package. To avoid this, rename or discard the duplicate files, or enable the Retain Folder Structure option.\n\n{0} duplicate file(s) found:\n{1}</value>
</data>
<data name="DuplicateFilesInPublishWarningTitle" xml:space="preserve">
<value>Duplicate Files</value>
</data>
<data name="NodeInCanvasSearchCreationError" xml:space="preserve">
<value>Failed to create node: </value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3970,6 +3970,12 @@ To make this file into a new template, save it to a different folder, then move
<data name="MessagePackOlderDynamoLink" xml:space="preserve">
<value>#Learn more=https://primer2.dynamobim.org/1_developer_primer_intro/3_developing_for_dynamo/updating-your-packages-and-dynamo-libraries-for-dynamo-3x-net8</value>
</data>
<data name="DuplicateFilesInPublishWarningMessage" xml:space="preserve">
<value>Files with same name will be overwritten in the final package. To avoid this, rename or discard the duplicate files, or enable the Retain Folder Structure option.\n\n{0} duplicate file(s) found:\n{1}</value>
</data>
<data name="DuplicateFilesInPublishWarningTitle" xml:space="preserve">
<value>Duplicate Files</value>
</data>
<data name="NodeInCanvasSearchCreationError" xml:space="preserve">
<value>Failed to create node: </value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,8 @@ Dynamo.UI.IViewModelView<T>.ViewModel.get -> T
Dynamo.UI.Prompts.DynamoMessageBox
Dynamo.UI.Prompts.DynamoMessageBox.BodyText.get -> string
Dynamo.UI.Prompts.DynamoMessageBox.BodyText.set -> void
Dynamo.UI.Prompts.DynamoMessageBox.DialogFlags
Dynamo.UI.Prompts.DynamoMessageBox.DialogFlags.Scrollable = 0 -> Dynamo.UI.Prompts.DynamoMessageBox.DialogFlags
Dynamo.UI.Prompts.DynamoMessageBox.DialogResult.get -> bool?
Dynamo.UI.Prompts.DynamoMessageBox.DialogResult.set -> void
Dynamo.UI.Prompts.DynamoMessageBox.DynamoMessageBox() -> void
Expand Down Expand Up @@ -4288,6 +4290,7 @@ static Dynamo.UI.Prompts.DynamoMessageBox.Show(string messageBoxText, string cap
static Dynamo.UI.Prompts.DynamoMessageBox.Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button) -> System.Windows.MessageBoxResult
static Dynamo.UI.Prompts.DynamoMessageBox.Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, string tooltip = "") -> System.Windows.MessageBoxResult
static Dynamo.UI.Prompts.DynamoMessageBox.Show(System.Windows.Window owner, string messageBoxText, string caption, bool showRichTextBox, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon) -> System.Windows.MessageBoxResult
static Dynamo.UI.Prompts.DynamoMessageBox.Show(System.Windows.Window owner, string messageBoxText, string caption, System.Collections.Generic.Dictionary<Dynamo.UI.Prompts.DynamoMessageBox.DialogFlags, bool> flags, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon) -> System.Windows.MessageBoxResult
static Dynamo.UI.Prompts.DynamoMessageBox.Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon) -> System.Windows.MessageBoxResult
static Dynamo.UI.SharedDictionaryManager.ConnectorsDictionary.get -> System.Windows.ResourceDictionary
static Dynamo.UI.SharedDictionaryManager.ConnectorsDictionaryUri.get -> System.Uri
Expand Down Expand Up @@ -4473,6 +4476,8 @@ static Dynamo.Wpf.Properties.Resources.DisablePackageInstallIconTooltip.get -> s
static Dynamo.Wpf.Properties.Resources.DiscardChangesWarningPopupCaption.get -> string
static Dynamo.Wpf.Properties.Resources.DiscardChangesWarningPopupMessage.get -> string
static Dynamo.Wpf.Properties.Resources.DownloadWarningMessageBoxTitle.get -> string
static Dynamo.Wpf.Properties.Resources.DuplicateFilesInPublishWarningMessage.get -> string
static Dynamo.Wpf.Properties.Resources.DuplicateFilesInPublishWarningTitle.get -> string
static Dynamo.Wpf.Properties.Resources.DynamoShowFileTrustWarning.get -> string
static Dynamo.Wpf.Properties.Resources.DynamoUpdateAvailableToolTip.get -> string
static Dynamo.Wpf.Properties.Resources.DynamoViewCancelButtonTooltip.get -> string
Expand Down Expand Up @@ -5502,6 +5507,7 @@ static Dynamo.Wpf.Utilities.MessageBoxService.Show(string msg, string title, boo
static Dynamo.Wpf.Utilities.MessageBoxService.Show(string msg, string title, System.Windows.MessageBoxButton button, System.Collections.Generic.IEnumerable<string> buttonNames, System.Windows.MessageBoxImage img) -> System.Windows.MessageBoxResult
static Dynamo.Wpf.Utilities.MessageBoxService.Show(string msg, string title, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage img) -> System.Windows.MessageBoxResult
static Dynamo.Wpf.Utilities.MessageBoxService.Show(System.Windows.Window owner, string msg, string title, bool showRichTextBox, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage img) -> System.Windows.MessageBoxResult
static Dynamo.Wpf.Utilities.MessageBoxService.Show(System.Windows.Window owner, string msg, string title, System.Collections.Generic.Dictionary<Dynamo.UI.Prompts.DynamoMessageBox.DialogFlags, bool> flags, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage img) -> System.Windows.MessageBoxResult
static Dynamo.Wpf.Utilities.MessageBoxService.Show(System.Windows.Window owner, string msg, string title, System.Windows.MessageBoxButton button, System.Collections.Generic.IEnumerable<string> buttonNames, System.Windows.MessageBoxImage img) -> System.Windows.MessageBoxResult
static Dynamo.Wpf.Utilities.MessageBoxService.Show(System.Windows.Window owner, string msg, string title, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage img) -> System.Windows.MessageBoxResult
static Dynamo.Wpf.Utilities.WebView2Utilities.ValidateWebView2RuntimeInstalled() -> bool
Expand Down
16 changes: 14 additions & 2 deletions src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,27 @@

<!-- Body Text -->
<TextBlock Name="BodyTextBlock"
Grid.Row="1"
Margin="20"
Margin="20"
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="14px"
Foreground="#3C3C3C"
Text="{Binding BodyText, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<!-- Body text in scrollable text box -->
<ScrollViewer Name="ScrollableBodyTextBlock" VerticalScrollBarVisibility="Auto"
Margin="20" MaxHeight="250" Grid.Row="1" Visibility="Collapsed">
<TextBlock
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="14px"
Foreground="#3C3C3C"
Text="{Binding BodyText, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
</ScrollViewer>
<!-- Body text in custom rich text box, mostly used in guided tours -->
<localui:CustomRichTextBox x:Name="ContentRichTextBox"
IsDocumentEnabled="True"
Visibility="Collapsed"
Expand Down
45 changes: 45 additions & 0 deletions src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public MessageBoxImage MessageBoxImage
/// </summary>
public string Tooltip { get; private set; }

/// <summary>
/// A list of customization options for dialog box
/// </summary>
public enum DialogFlags
{
//Enables scrollable text in the message box
Scrollable = 0,
}

#endregion

/// <summary>
Expand Down Expand Up @@ -204,6 +213,7 @@ public static MessageBoxResult Show(Window owner, string messageBoxText, string
dynamoMessageBox.ShowDialog();
return dynamoMessageBox.CustomDialogResult;
}

/// <summary>
/// Displays a dialog to the user and returns their choice as a MessageBoxResult.
/// </summary>
Expand Down Expand Up @@ -234,6 +244,41 @@ public static MessageBoxResult Show(Window owner,string messageBoxText, string c
return dynamoMessageBox.CustomDialogResult;
}

/// <summary>
/// Displays a dialog to the user and returns their choice as a MessageBoxResult.
/// </summary>
/// <param name="owner">owning window of the messagebox</param>
/// <param name="messageBoxText">Content of the message</param>
/// <param name="caption">MessageBox title</param>
/// <param name="flags">Provide a list of flags that can be used to customize the dialog box, e.g Scrollable</param>
/// <param name="button">Type of button shown in the MessageBox: Ok, OkCancel; etc</param>
/// <param name="icon">Type of message: Warning, Error</param>
/// <returns></returns>
public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, Dictionary<DialogFlags, bool> flags, MessageBoxButton button,
MessageBoxImage icon)
{
var dynamoMessageBox = new DynamoMessageBox
{
BodyText = messageBoxText,
TitleText = caption,
MessageBoxButton = button,
MessageBoxImage = icon
};
if (owner != null && owner.IsLoaded)
{
dynamoMessageBox.Owner = owner;
}

if (flags.TryGetValue(DialogFlags.Scrollable, out bool scrollable) && scrollable)
{
dynamoMessageBox.BodyTextBlock.Visibility = Visibility.Collapsed;
dynamoMessageBox.ScrollableBodyTextBlock.Visibility = Visibility.Visible;
}
dynamoMessageBox.ConfigureButtons(button);
dynamoMessageBox.ShowDialog();
return dynamoMessageBox.CustomDialogResult;
}

/// <summary>
/// Displays a dialog to the user and returns their choice as a MessageBoxResult.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Utilities/MessageBoxUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal interface IMessageBox
MessageBoxResult Show(string msg, string title, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(string msg, string title, bool showRichTextBox, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(Window owner, string msg, string title, bool showRichTextBox, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(Window owner, string msg, string title, Dictionary<DynamoMessageBox.DialogFlags, bool> flags, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(Window owner,string msg, string title, MessageBoxButton button, MessageBoxImage img);
MessageBoxResult Show(Window owner, string msg, string title, MessageBoxButton button, IEnumerable<string> buttonNames, MessageBoxImage img);
MessageBoxResult Show(string msg, string title, MessageBoxButton button, IEnumerable<string> buttonNames, MessageBoxImage img);
Expand All @@ -34,6 +35,10 @@ MessageBoxResult IMessageBox.Show(Window owner, string msg, string title, bool s
{
return DynamoMessageBox.Show(owner,msg, title, showRichTextBox, button, img);
}
MessageBoxResult IMessageBox.Show(Window owner, string msg, string title, Dictionary<DynamoMessageBox.DialogFlags, bool> flags, MessageBoxButton button, MessageBoxImage img)
{
return DynamoMessageBox.Show(owner, msg, title, flags, button, img);
}

public MessageBoxResult Show(Window owner, string msg, string title, MessageBoxButton button, MessageBoxImage img)
{
Expand Down Expand Up @@ -68,6 +73,10 @@ public static MessageBoxResult Show(Window owner, string msg, string title, bool
{
return (msg_box ?? (msg_box = new DefaultMessageBox())).Show(owner,msg, title, showRichTextBox, button, img);
}
public static MessageBoxResult Show(Window owner, string msg, string title, Dictionary<DynamoMessageBox.DialogFlags, bool> flags, MessageBoxButton button, MessageBoxImage img)
{
return (msg_box ?? (msg_box = new DefaultMessageBox())).Show(owner, msg, title, flags, button, img);
}
public static MessageBoxResult Show(Window owner,string msg, string title, MessageBoxButton button, MessageBoxImage img)
{
return (msg_box ?? (msg_box = new DefaultMessageBox())).Show(owner,msg, title, button, img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,22 @@ private void PreviewPackageBuild()
return;

var files = GetAllFiles().ToList();
if (!RetainFolderStructureOverride)
{
//Look for duplicate filenames to alert user
var duplicateFiles = files.GroupBy(x => Path.GetFileName(x))
.Where(x => x.Count() > 1)
.ToList();
if (duplicateFiles.Count > 0)
{
if (!DynamoModel.IsTestMode)
{
var DialogOptions = new Dictionary<Dynamo.UI.Prompts.DynamoMessageBox.DialogFlags, bool>() { { Dynamo.UI.Prompts.DynamoMessageBox.DialogFlags.Scrollable, true } };
MessageBoxService.Show(System.Windows.Application.Current?.MainWindow, string.Format(Resources.DuplicateFilesInPublishWarningMessage.Replace("\\n", Environment.NewLine), duplicateFiles.Count, string.Join("\n", duplicateFiles.Select(x => x.Key).ToList())), Resources.DuplicateFilesInPublishWarningTitle, DialogOptions, MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
}

files = files.GroupBy(file => Path.GetFileName(file), StringComparer.OrdinalIgnoreCase)
.Select(group => group.First())
.ToList();
Expand Down
Loading