Skip to content

Commit

Permalink
Renamed user.* to user_feedback.*.
Browse files Browse the repository at this point in the history
Moved "find missing elements" code from main.cpp to user_feedback.cpp.
#115.
  • Loading branch information
end2endzone committed Jan 9, 2024
1 parent d607d91 commit 806b3f5
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/refresh_file_explorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ add_executable(refresh_file_explorer WIN32
main.cpp
main.h
targetver.h
user.cpp
user.h
user_feedback.cpp
user_feedback.h
)

# Group external files as filter for Visual Studio
Expand Down
35 changes: 34 additions & 1 deletion src/refresh_file_explorer/file_explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://forums.codeguru.com/showthread.php?345012-Access-violation-using-CComPtr-lt-gt

#include "file_explorer.h"
#include "user.h"
#include "user_feedback.h"

#include <objbase.h>
#include <comdef.h>
Expand Down Expand Up @@ -322,4 +322,37 @@ bool KillFileExplorerProcesses()
process_ids = GetFileExplorerProcessIds();
bool success = (process_ids.empty());
return success;
}

bool FindMissingElements(const Utf8FileList& previous, Utf8FileList& output)
{
output.clear();

// Check again the path of each File Explorer windows
Utf8FileList current;
bool success = GetFileExplorerWindowPaths(current);
if (!success)
return false;

// Remove from the missing list every path that we succesfully restored.
for (size_t i = 0; i < previous.size(); i++)
{
const std::string previous_path = previous[i];

// Is t still missing ?
bool found = FindPath(previous, previous_path);

if (!found)
{
// Still missing...
output.push_back(previous_path);
}
}

// Debugging and testing...
// Force simulate a last missing path.
//output.clear();
//output.push_back("foobar");

return true;
}
10 changes: 9 additions & 1 deletion src/refresh_file_explorer/file_explorer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "user.h"
#include "user_feedback.h"

#include <string>
#include <vector>
Expand Down Expand Up @@ -53,3 +53,11 @@ std::string GetFileExplorerExecPath();
/// </summary>
/// <returns>Returns true when the operation is succesful. Returns false otherwise.</returns>
bool KillFileExplorerProcesses();

/// <summary>
/// Find elements from a previous call to GetFileExplorerWindowPaths() that are missing from a recent call to GetFileExplorerWindowPaths().
/// </summary>
/// <param name="previous">The paths found from a previous call to GetFileExplorerWindowPaths().</param>
/// <param name="output">The out paths that are missing.</param>
/// <returns>Returns true when the operation is succesful. Returns false otherwise.</returns>
bool FindMissingElements(const Utf8FileList& previous, Utf8FileList & output);
31 changes: 5 additions & 26 deletions src/refresh_file_explorer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "framework.h"
#include "main.h"
#include "user.h"
#include "user_feedback.h"
#include "file_explorer.h"

#include "rapidassist/unicode.h"
Expand Down Expand Up @@ -276,8 +276,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
KillTimer(hWnd, uCleanupIDEvent);

// Check again the path of each File Explorer windows
Utf8FileList restored;
success = GetFileExplorerWindowPaths(restored);
Utf8FileList tmp;
success = FindMissingElements(paths_missing, tmp);
if (!success)
{
std::wstring str;
Expand All @@ -287,27 +287,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}

// Remove from the missing list every path that we succesfully restored.
Utf8FileList tmp;
for (size_t i = 0; i < paths_missing.size(); i++)
{
const std::string missing_path = paths_missing[i];

// Is t still missing ?
bool found = FindPath(restored, missing_path);

if (!found)
{
// Still missing...
tmp.push_back(missing_path);
}
}

// Debugging and testing...
// Force simulate a last missing path.
//tmp.clear();
//tmp.push_back("foobar");

bool has_changed = (paths_missing != tmp);
paths_missing = tmp;

Expand All @@ -326,12 +305,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
std::wstring str;
str += L"All File Explorer windows has been restored.\n"
L"Press OK to close the application.";
MessageBoxCentered(hWnd, str.c_str(), L"Operation succesful", MB_OK | MB_ICONINFORMATION);
ShowSuccessMessage(hWnd, str);
PostQuitMessage(EXIT_SUCCESS_NO_ERROR);
return 0;
}

// No? Then wait for the time to look again...
// No? Wait then to look again...
uCleanupIDEvent = SetTimer(hWnd, IDT_TIMER1, 1000, (TIMERPROC)NULL);
break;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Windows.h>
#include "user.h"
#include "user_feedback.h"

#include "rapidassist/process_utf8.h"
#include "rapidassist/filesystem_utf8.h"
Expand Down Expand Up @@ -31,6 +31,11 @@ void ShowErrorMessage(HWND hWnd, const std::wstring& message)
MessageBoxCentered(hWnd, message.c_str(), title.c_str(), MB_OK | MB_ICONERROR);
}

void ShowSuccessMessage(HWND hWnd, const std::wstring& message)
{
MessageBoxCentered(hWnd, message.c_str(), L"Operation succesful", MB_OK | MB_ICONINFORMATION);
}

bool GetUserConfirmation(HWND hWnd)
{
if (hWnd == NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ void ShowErrorMessage(const std::wstring& message);
/// <param name="hWnd">The parent window.</param>
void ShowErrorMessage(HWND hWnd, const std::wstring& message);

/// <summary>
/// Show an generic operation successful message to the user.
/// </summary>
/// <param name="hWnd">The parent window.</param>
void ShowSuccessMessage(HWND hWnd, const std::wstring& message);

/// <summary>
/// Ask for the user's confirmation before proceeding.
/// </summary>
Expand Down

0 comments on commit 806b3f5

Please sign in to comment.