Skip to content

Commit

Permalink
sort files alphabetically and remove dupes
Browse files Browse the repository at this point in the history
also fix left arrow key in main
  • Loading branch information
Like4Schnitzel committed Feb 26, 2024
1 parent b2acc7f commit 56e5558
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/media-viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(int argc, char** argv)

// left arrow
if (kp.keyValue == 1792836)
cout << "Selected file: " << mv.current()->path << "\n";
cout << "Selected file: " << mv.prev()->path << "\n";

// ESC
if (kp.keyValue == 27)
Expand Down
9 changes: 8 additions & 1 deletion src/media-viewer/mediaviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ MediaViewer::MediaViewer(const std::filesystem::path path)
}

int i = 0;
for (const auto file : VariousUtils::getFilesInDir(dirPath))
auto unfilteredFiles = VariousUtils::getFilesInDir(dirPath);
sort(unfilteredFiles.begin(), unfilteredFiles.end(), [](dirent d1, dirent d2){return (std::string)d1.d_name < (std::string)d2.d_name;});
for (const auto file : unfilteredFiles)
{
auto dirPathCopy = dirPath;
std::string pathFileName = dirPath.concat(file.d_name);
Expand Down Expand Up @@ -71,6 +73,11 @@ MediaViewer::MediaViewer(const std::filesystem::path path)
}
else if (validVTDI(pathFileName))
{
// VTDI file might have already been added in a previous mp4 check. Make sure it's not a dupe.
if (!std::none_of(files.begin(), files.end(), [&pathFileName](File d){return std::strcmp(d.path.c_str(), pathFileName.c_str()) == 0;}))
{
continue;
}
if (pathFileName == path)
{
filesIndex = i;
Expand Down
1 change: 1 addition & 0 deletions src/media-viewer/mediaviewer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <filesystem>
#include <bits/stdc++.h>
#include "../transcoder/videotranscoder.hpp"
#include "../decoder/vtdidecoder.hpp"
#include "../img-viewer/imgviewer.hpp"
Expand Down

0 comments on commit 56e5558

Please sign in to comment.