Skip to content

Commit

Permalink
My attempt at Paul's Search Log files for Show Folder Paths Dialog, S…
Browse files Browse the repository at this point in the history
…ort Backups Folder List, remove boost build configs, start experimenting with building ARM64
  • Loading branch information
computergeek1507 committed Dec 20, 2024
1 parent 6bb725f commit 68ba944
Show file tree
Hide file tree
Showing 14 changed files with 727 additions and 85 deletions.
27 changes: 15 additions & 12 deletions xLights/RestoreBackupDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ struct BModel {
};

//(*IdInit(RestoreBackupDialog)
const long RestoreBackupDialog::ID_STATICTEXT1 = wxNewId();
const long RestoreBackupDialog::ID_LISTBOX_BACKUPS = wxNewId();
const long RestoreBackupDialog::ID_PANEL1 = wxNewId();
const long RestoreBackupDialog::ID_CHECKLISTBOX_LAYOUT = wxNewId();
const long RestoreBackupDialog::ID_TREECTRL_LAYOUT = wxNewId();
const long RestoreBackupDialog::ID_SPLITTERWINDOW2 = wxNewId();
const long RestoreBackupDialog::ID_CHECKLISTBOX_SEQUENCES = wxNewId();
const long RestoreBackupDialog::ID_NOTEBOOK1 = wxNewId();
const long RestoreBackupDialog::ID_SPLITTERWINDOW1 = wxNewId();
const long RestoreBackupDialog::ID_STATICTEXT_BACKUPFOLDER = wxNewId();
const long RestoreBackupDialog::ID_BUTTON_RUN = wxNewId();
const wxWindowID RestoreBackupDialog::ID_STATICTEXT1 = wxNewId();
const wxWindowID RestoreBackupDialog::ID_LISTBOX_BACKUPS = wxNewId();
const wxWindowID RestoreBackupDialog::ID_PANEL1 = wxNewId();
const wxWindowID RestoreBackupDialog::ID_CHECKLISTBOX_LAYOUT = wxNewId();
const wxWindowID RestoreBackupDialog::ID_TREECTRL_LAYOUT = wxNewId();
const wxWindowID RestoreBackupDialog::ID_SPLITTERWINDOW2 = wxNewId();
const wxWindowID RestoreBackupDialog::ID_CHECKLISTBOX_SEQUENCES = wxNewId();
const wxWindowID RestoreBackupDialog::ID_NOTEBOOK1 = wxNewId();
const wxWindowID RestoreBackupDialog::ID_SPLITTERWINDOW1 = wxNewId();
const wxWindowID RestoreBackupDialog::ID_STATICTEXT_BACKUPFOLDER = wxNewId();
const wxWindowID RestoreBackupDialog::ID_BUTTON_RUN = wxNewId();
//*)

BEGIN_EVENT_TABLE(RestoreBackupDialog,wxDialog)
Expand Down Expand Up @@ -258,10 +258,13 @@ void RestoreBackupDialog::ListBackupDir()
wxString folder;
bool fcont = directory.GetFirst(&folder, "*");

wxArrayString dirList;
while (fcont) {
ListBoxBackups->Append(folder);
dirList.Add(folder);
fcont = directory.GetNext(&folder);
}
dirList.Sort(true);
ListBoxBackups->Append(dirList);
}

void RestoreBackupDialog::PopulateLayoutDataBox(wxString const& folder)
Expand Down
22 changes: 11 additions & 11 deletions xLights/RestoreBackupDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ class RestoreBackupDialog: public wxDialog
protected:

//(*Identifiers(RestoreBackupDialog)
static const long ID_STATICTEXT1;
static const long ID_LISTBOX_BACKUPS;
static const long ID_PANEL1;
static const long ID_CHECKLISTBOX_LAYOUT;
static const long ID_TREECTRL_LAYOUT;
static const long ID_SPLITTERWINDOW2;
static const long ID_CHECKLISTBOX_SEQUENCES;
static const long ID_NOTEBOOK1;
static const long ID_SPLITTERWINDOW1;
static const long ID_STATICTEXT_BACKUPFOLDER;
static const long ID_BUTTON_RUN;
static const wxWindowID ID_STATICTEXT1;
static const wxWindowID ID_LISTBOX_BACKUPS;
static const wxWindowID ID_PANEL1;
static const wxWindowID ID_CHECKLISTBOX_LAYOUT;
static const wxWindowID ID_TREECTRL_LAYOUT;
static const wxWindowID ID_SPLITTERWINDOW2;
static const wxWindowID ID_CHECKLISTBOX_SEQUENCES;
static const wxWindowID ID_NOTEBOOK1;
static const wxWindowID ID_SPLITTERWINDOW1;
static const wxWindowID ID_STATICTEXT_BACKUPFOLDER;
static const wxWindowID ID_BUTTON_RUN;
//*)

private:
Expand Down
224 changes: 224 additions & 0 deletions xLights/ShowFolderSearchDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/***************************************************************
* This source files comes from the xLights project
* https://www.xlights.org
* https://github.com/xLightsSequencer/xLights
* See the github commit history for a record of contributing
* developers.
* Copyright claimed based on commit dates recorded in Github
* License: https://github.com/xLightsSequencer/xLights/blob/master/License.txt
**************************************************************/

#include "ShowFolderSearchDialog.h"

//(*InternalHeaders(ShowFolderSearchDialog)
#include <wx/intl.h>
#include <wx/string.h>
//*)

#include <wx/dir.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include "ExternalHooks.h"
#include "xLightsMain.h"

#include <log4cpp/Category.hh>
#include <wx/regex.h>

//(*IdInit(ShowFolderSearchDialog)
const wxWindowID ShowFolderSearchDialog::ID_LISTCTRL_FOLDERS = wxNewId();
const wxWindowID ShowFolderSearchDialog::ID_STATICTEXT_BACKUPFOLDER = wxNewId();
const wxWindowID ShowFolderSearchDialog::ID_BUTTON_TEMP = wxNewId();
const wxWindowID ShowFolderSearchDialog::ID_BUTTON_PERMANENT = wxNewId();
const wxWindowID ShowFolderSearchDialog::ID_BUTTON_OPEN = wxNewId();
//*)

BEGIN_EVENT_TABLE(ShowFolderSearchDialog,wxDialog)
//(*EventTable(ShowFolderSearchDialog)
//*)

END_EVENT_TABLE()

ShowFolderSearchDialog::ShowFolderSearchDialog(xLightsFrame* parent)
{
//(*Initialize(ShowFolderSearchDialog)
wxBoxSizer* BoxSizer1;
wxFlexGridSizer* FlexGridSizer1;

Create(parent, wxID_ANY, _("Find Show Folder Dialog"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxMINIMIZE_BOX, _T("wxID_ANY"));
SetClientSize(wxDLG_UNIT(parent,wxSize(400,400)));
SetMinSize(wxSize(800,400));
FlexGridSizer1 = new wxFlexGridSizer(3, 1, 0, 0);
FlexGridSizer1->AddGrowableCol(0);
FlexGridSizer1->AddGrowableRow(0);
ListCtrl_Folders = new wxListCtrl(this, ID_LISTCTRL_FOLDERS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL, wxDefaultValidator, _T("ID_LISTCTRL_FOLDERS"));
FlexGridSizer1->Add(ListCtrl_Folders, 0, wxEXPAND, 5);
StaticTextBackUpFolder = new wxStaticText(this, ID_STATICTEXT_BACKUPFOLDER, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, _T("ID_STATICTEXT_BACKUPFOLDER"));
FlexGridSizer1->Add(StaticTextBackUpFolder, 1, wxALL|wxEXPAND, 5);
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
ButtonTemp = new wxButton(this, ID_BUTTON_TEMP, _("Change Temporary"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON_TEMP"));
BoxSizer1->Add(ButtonTemp, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
ButtonPermanent = new wxButton(this, ID_BUTTON_PERMANENT, _("Change Permanently"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON_PERMANENT"));
BoxSizer1->Add(ButtonPermanent, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
ButtonOpen = new wxButton(this, ID_BUTTON_OPEN, _("Open in Explorer"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON_OPEN"));
BoxSizer1->Add(ButtonOpen, 0, wxALL, 5);
BoxSizer1->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer1->Add(BoxSizer1, 1, wxALL|wxEXPAND, 5);
SetSizer(FlexGridSizer1);
Layout();

Connect(ID_LISTCTRL_FOLDERS, wxEVT_COMMAND_LIST_ITEM_SELECTED, (wxObjectEventFunction)&ShowFolderSearchDialog::OnListCtrl_FoldersItemSelect);
Connect(ID_BUTTON_TEMP, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ShowFolderSearchDialog::OnButtonTempClick);
Connect(ID_BUTTON_PERMANENT, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ShowFolderSearchDialog::OnButtonPermanentClick);
Connect(ID_BUTTON_OPEN, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ShowFolderSearchDialog::OnButtonOpenClick);
//*)

ListCtrl_Folders->AppendColumn("Folder", wxLIST_FORMAT_LEFT,
wxLIST_AUTOSIZE);
ListCtrl_Folders->AppendColumn("Opens", wxLIST_FORMAT_CENTRE);

_xLights = parent;
auto const& folder = FindLogFolder();
auto const& files = FindLogFiles(folder);
FindShowFolders(files, folder);
ValidateWindow();
}


ShowFolderSearchDialog::~ShowFolderSearchDialog()
{
//(*Destroy(ShowFolderSearchDialog)
//*)
}

void ShowFolderSearchDialog::OnInit(wxInitDialogEvent& event)
{
Layout();
}

void ShowFolderSearchDialog::ValidateWindow()
{
ButtonOpen->Enable(ListCtrl_Folders->GetSelectedItemCount() > 0);
ButtonPermanent->Enable(ListCtrl_Folders->GetSelectedItemCount() > 0);
ButtonTemp->Enable(ListCtrl_Folders->GetSelectedItemCount() > 0);
}

wxString ShowFolderSearchDialog::FindLogFolder() const
{
static log4cpp::Category& logger_base = log4cpp::Category::getInstance(std::string("log_base"));
wxString dir;
#ifdef __WXMSW__
wxGetEnv("APPDATA", &dir);
if (dir.EndsWith("/") || dir.EndsWith("\\")) {
dir = dir.Left(dir.Length() - 1);
}
dir = dir + wxFileName::GetPathSeparator();
#endif
#ifdef __WXOSX__
wxFileName home;
home.AssignHomeDir();
dir = home.GetFullPath();
if (dir.EndsWith("/")) {
dir = dir.Left(dir.Length() - 1);
}
dir = dir + "/Library/Logs/";
#endif
#ifdef __LINUX__
dir = "/tmp/";
#endif
if (!wxDir::Exists(dir)) {
if (wxDir::Exists(xLightsFrame::CurrentDir + wxFileName::GetPathSeparator())) {
dir = xLightsFrame::CurrentDir + wxFileName::GetPathSeparator();
} else if (wxDir::Exists(wxGetCwd() + wxFileName::GetPathSeparator())) {
dir = wxGetCwd() + wxFileName::GetPathSeparator();
}
}
return dir;
}

wxArrayString ShowFolderSearchDialog::FindLogFiles(wxString const& folder) const{
wxArrayString files;
GetAllFilesInDir(folder, files, "xLights_l4cpp.log*", wxDIR_DEFAULT);
files.Sort();
return files;
}

void ShowFolderSearchDialog::FindShowFolders(wxArrayString const& logs, wxString const& folder) {
std::map<wxString, int> showFolders;
//Show directory set to : D:\lights_data\cubicle.
static wxRegEx logregex("Show directory set to : (.*)\\.");
wxProgressDialog dlg("Searching " + folder, "Searching " + folder, logs.size(), this, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT);
dlg.Show();
int i{ 0 };
for (auto const& log : logs) {
if (FileExists(log)) {
dlg.Update(i, "Reading " + log);
wxFileName fn(log);
wxFileInputStream input(fn.GetFullPath());
if (input.IsOk()) {
wxTextInputStream text(input);
while (!input.Eof()) {
wxString const& line = text.ReadLine();
dlg.Pulse();
if (line.Contains("Show directory set to")) {
if (logregex.Matches(line)) {
wxString const& folder = logregex.GetMatch(line, 1);
if (wxDir::Exists(folder)) {
if (showFolders.find(folder) == showFolders.end()) {
showFolders[folder] = 1;
} else {
showFolders[folder]++;
}
}
}
}
}
}
}
if (dlg.WasCancelled()) {
break;
}
#if defined(_DEBUG)
break;
#endif
++i;
}

ListCtrl_Folders->Freeze();
ListCtrl_Folders->DeleteAllItems();

for (auto const& [folder,opens ]: showFolders) {
auto item = ListCtrl_Folders->InsertItem(ListCtrl_Folders->GetItemCount(), folder);
ListCtrl_Folders->SetItem(item, 1, wxString::Format("%i", opens));
}
ListCtrl_Folders->SetColumnWidth(0, wxLIST_AUTOSIZE);
ListCtrl_Folders->Thaw();
}

void ShowFolderSearchDialog::OnListCtrl_FoldersItemSelect(wxListEvent& event)
{
StaticTextBackUpFolder->SetLabelText(event.GetLabel());
_selectedFolder = event.GetLabel();
ValidateWindow();
}

void ShowFolderSearchDialog::OnButtonTempClick(wxCommandEvent& event)
{
if (!_selectedFolder.empty()) {
_xLights->SetDir(_selectedFolder, false);
}
EndDialog(0);
}

void ShowFolderSearchDialog::OnButtonPermanentClick(wxCommandEvent& event)
{
if (!_selectedFolder.empty()) {
_xLights->SetDir(_selectedFolder, true);
}
EndDialog(0);
}

void ShowFolderSearchDialog::OnButtonOpenClick(wxCommandEvent& event) {
if (!_selectedFolder.empty()) {
wxLaunchDefaultApplication(_selectedFolder);
}
}
71 changes: 71 additions & 0 deletions xLights/ShowFolderSearchDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

/***************************************************************
* This source files comes from the xLights project
* https://www.xlights.org
* https://github.com/xLightsSequencer/xLights
* See the github commit history for a record of contributing
* developers.
* Copyright claimed based on commit dates recorded in Github
* License: https://github.com/xLightsSequencer/xLights/blob/master/License.txt
**************************************************************/

//(*Headers(ShowFolderSearchDialog)
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/listctrl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
//*)

#include <wx/treelist.h>
#include <wx/progdlg.h>

class wxMouseEvent;
class wxCommandEvent;
class xLightsFrame;

class ShowFolderSearchDialog: public wxDialog
{
xLightsFrame* _xLights = nullptr;
wxString _selectedFolder;

public:
ShowFolderSearchDialog(xLightsFrame* parent);
virtual ~ShowFolderSearchDialog();

//(*Declarations(ShowFolderSearchDialog)
wxButton* ButtonOpen;
wxButton* ButtonPermanent;
wxButton* ButtonTemp;
wxListCtrl* ListCtrl_Folders;
wxStaticText* StaticTextBackUpFolder;
//*)

protected:
//(*Identifiers(ShowFolderSearchDialog)
static const wxWindowID ID_LISTCTRL_FOLDERS;
static const wxWindowID ID_STATICTEXT_BACKUPFOLDER;
static const wxWindowID ID_BUTTON_TEMP;
static const wxWindowID ID_BUTTON_PERMANENT;
static const wxWindowID ID_BUTTON_OPEN;
//*)


private:

void ValidateWindow();
wxString FindLogFolder() const;
wxArrayString FindLogFiles(wxString const& folder) const;
void FindShowFolders(wxArrayString const& logs, wxString const& folder);

public:
//(*Handlers(ShowFolderSearchDialog)
void OnInit(wxInitDialogEvent& event);
void OnListCtrl_FoldersItemSelect(wxListEvent& event);
void OnButtonTempClick(wxCommandEvent& event);
void OnButtonPermanentClick(wxCommandEvent& event);
void OnButtonOpenClick(wxCommandEvent& event);
//*)
DECLARE_EVENT_TABLE()
};
Loading

0 comments on commit 68ba944

Please sign in to comment.