Skip to content

Commit

Permalink
Include yellow warning for path or filename contains unsupported chars
Browse files Browse the repository at this point in the history
  • Loading branch information
derwin12 authored and dkulp committed Jan 14, 2025
1 parent 3d7b5d5 commit 0cab656
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
8 changes: 4 additions & 4 deletions xLights/BulkEditControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ void BulkEditFilePickerCtrl::ValidateControl()
GetTextCtrl()->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
} else {
auto file = GetFileName().GetFullPath();
if (file.Contains(',')) {
GetTextCtrl()->SetBackgroundColour(*wxYELLOW);
SetToolTip("File " + file + " contains characters in the path or filename that will cause issues in xLights. Please rename it.");
} else if (!FileExists(file)) {
if (!FileExists(file)) {
GetTextCtrl()->SetBackgroundColour(*wxRED);
SetToolTip("File " + file + " does not exist.");
} else if (!file.empty() && !IsXmlSafe(file)) {
GetTextCtrl()->SetBackgroundColour(*wxYELLOW);
SetToolTip("File " + file + " contains characters in the path or filename that will cause issues in xLights. Please rename it.");
} else {
if (GetToolTipText() != "") { // we do this because setting tooltips seems slow
SetToolTip("");
Expand Down
14 changes: 14 additions & 0 deletions xLights/UtilFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,20 @@ std::string XmlSafe(const std::string& s) {
return res;
}

bool IsXmlSafe(const std::string& s) {
bool res = true;
for (auto c = s.begin(); c != s.end(); ++c) {
if ((int)(*c) < 32 || (int)(*c) > 127) {
res = false;
} else if (*c == ',') {
res = false;
} else if (*c == '\'') {
res = false;
}
}
return res;
}

// This takes a string and removes all problematic characters from it for an XML file
std::string RemoveUnsafeXmlChars(const std::string& s) {
std::string res;
Expand Down
1 change: 1 addition & 0 deletions xLights/UtilFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool IsVersionOlder(const std::string &compare, const std::string &version);
std::string JSONSafe(const std::string& s);
std::string UnXmlSafe(const std::string &s);
std::string XmlSafe(const std::string& s);
bool IsXmlSafe(const std::string& s);
std::string RemoveUnsafeXmlChars(const std::string& s);
std::string EscapeCSV(const std::string& s);
std::string EscapeRegex(const std::string& s);
Expand Down
13 changes: 12 additions & 1 deletion xLights/effects/PicturesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "EffectPanelUtils.h"
#include "GIFImage.h"
#include "../ExternalHooks.h"
#include "UtilFunctions.h"

//(*IdInit(PicturesPanel)
const long PicturesPanel::ID_FILEPICKER_Pictures_Filename = wxNewId();
Expand Down Expand Up @@ -382,5 +383,15 @@ void PicturesPanel::ValidateWindow()
CheckBox_LoopGIF->Enable(enable);
CheckBox_SuppressGIFBackground->Enable(enable);

FilePickerCtrl1->SetToolTip(wxFileName(FilePickerCtrl1->GetFileName()).GetFullName());
auto file = FilePickerCtrl1->GetFileName().GetFullPath();
if (!file.empty() && !FileExists(file)) {
FilePickerCtrl1->SetBackgroundColour(*wxRED);
SetToolTip("File " + file + " does not exist.");
} else if (!file.empty() && !IsXmlSafe(file)) {
FilePickerCtrl1->SetBackgroundColour(*wxYELLOW);
SetToolTip("File " + file + " contains characters in the path or filename that will cause issues in xLights. Please rename it.");
} else {
FilePickerCtrl1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
SetToolTip(file);
}
}
14 changes: 14 additions & 0 deletions xLights/effects/ShaderPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../xLightsMain.h"
#include "../xLightsApp.h"
#include "../TimingPanel.h"
#include "UtilFunctions.h"

//(*InternalHeaders(ShaderPanel)
#include <wx/bitmap.h>
Expand Down Expand Up @@ -182,6 +183,17 @@ ShaderPanel::~ShaderPanel()

void ShaderPanel::ValidateWindow()
{
auto file = FilePickerCtrl1->GetFileName().GetFullPath();
if (!file.empty() && !FileExists(file)) {
FilePickerCtrl1->SetBackgroundColour(*wxRED);
SetToolTip("File " + file + " does not exist.");
} else if (!file.empty() && !IsXmlSafe(file)) {
FilePickerCtrl1->SetBackgroundColour(*wxYELLOW);
SetToolTip("File " + file + " contains characters in the path or filename that will cause issues in xLights. Please rename it.");
} else {
FilePickerCtrl1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
SetToolTip(file);
}
}

void ShaderPanel::OnFilePickerCtrl1FileChanged(wxFileDirPickerEvent& event)
Expand All @@ -196,6 +208,8 @@ void ShaderPanel::OnFilePickerCtrl1FileChanged(wxFileDirPickerEvent& event)
return;
}

ValidateWindow();

// restore time to defaults
BitmapButton_Shader_Speed->SetActive(false);
BitmapButton_Shader_Offset_X->SetActive(false);
Expand Down
13 changes: 12 additions & 1 deletion xLights/effects/VideoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ void VideoPanel::OnFilePicker_Video_FilenameFileChanged(wxFileDirPickerEvent& ev
Slider_Video_Starttime->SetMax(99999);
TextCtrl2->SetValue(FORMATTIME(0));
}
FilePicker_Video_Filename->SetToolTip(fn.GetFullName());
}

void VideoPanel::OnCheckBox_SynchroniseWithAudioClick(wxCommandEvent& event)
Expand Down Expand Up @@ -343,6 +342,18 @@ void VideoPanel::ValidateWindow()
TextCtrl_Video_Speed->Disable();
BitmapButton_Video_Speed->Disable();
}

auto file = FilePicker_Video_Filename->GetFileName().GetFullPath();
if (!file.empty() && !FileExists(file)) {
FilePicker_Video_Filename->SetBackgroundColour(*wxRED);
SetToolTip("File " + file + " does not exist.");
} else if (!file.empty() && !IsXmlSafe(file)) {
FilePicker_Video_Filename->SetBackgroundColour(*wxYELLOW);
SetToolTip("File " + file + " contains characters in the path or filename that will cause issues in xLights. Please rename it.");
} else {
FilePicker_Video_Filename->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
SetToolTip(file);
}
}

void VideoPanel::OnChoice_Video_DurationTreatmentSelect(wxCommandEvent& event)
Expand Down

0 comments on commit 0cab656

Please sign in to comment.