Skip to content

Commit

Permalink
Some random cleanup and targetting of new version of taglib
Browse files Browse the repository at this point in the history
  • Loading branch information
Zereges committed Aug 22, 2024
1 parent 0eb3c37 commit a4df286
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Usage: id3-tags-cli [options] file
[STR] - String type
[INT] - Integer type
If no argument is specified, information of given file is retrieved.
If no arguments are specified, information of given file is retrieved.
If the option is not specified, the value is unchanged.
If the argument is empty string ("") (for [STR]) or 0 (for [INT]) the value is cleared.
Expand Down
4 changes: 2 additions & 2 deletions id3-tags-cli.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "id3-tags-cli", "id3-tags-cli.vcxproj", "{2F93CC68-3189-4099-9E02-9CD5394305B5}"
EndProject
Expand Down
6 changes: 3 additions & 3 deletions id3-tags-cli.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{2f93cc68-3189-4099-9e02-9cd5394305b5}</ProjectGuid>
<RootNamespace>id3_tags_cli</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
26 changes: 14 additions & 12 deletions src/arguments.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// ReSharper disable CppClangTidyConcurrencyMtUnsafe
#pragma once
#include <string>
#include <optional>
#include <exception>

#include <getopt.h>

Expand Down Expand Up @@ -48,9 +48,11 @@ class arguments
static arguments parse_args(int argc, std::vector<std::string>& arg_vector)
{
std::vector<char*> argv;
argv.reserve(argc);
for (int i = 0; i < argc; ++i)
argv.push_back(arg_vector[i].data());
argv.push_back(nullptr);

opterr = 0; // getopt segfaults while trying to print an error

arguments args{false, false};
for (;;)
Expand Down Expand Up @@ -119,47 +121,47 @@ class arguments
return args;
}

bool is_help() const
[[nodiscard]] bool is_help() const
{
return m_help;
}

bool is_version() const
[[nodiscard]] bool is_version() const
{
return m_version;
}

const std::string& file_name() const
[[nodiscard]] const std::string& file_name() const
{
return m_file_name;
}

std::pair<bool, std::string> artist() const
[[nodiscard]] std::pair<bool, std::string> artist() const
{
return { m_artist.has_value(), m_artist.value_or("") };
}

std::pair<bool, std::string> title() const
[[nodiscard]] std::pair<bool, std::string> title() const
{
return { m_title.has_value(), m_title.value_or("") };
}

std::pair<bool, std::string> album() const
[[nodiscard]] std::pair<bool, std::string> album() const
{
return { m_album.has_value(), m_album.value_or("") };
}

std::pair<bool, std::string> year() const
[[nodiscard]] std::pair<bool, std::string> year() const
{
return { m_year.has_value(), m_year.value_or("") };
}

std::pair<bool, std::string> track() const
[[nodiscard]] std::pair<bool, std::string> track() const
{
return { m_track.has_value(), m_track.value_or("") };
}

std::pair<bool, std::string> genre() const
[[nodiscard]] std::pair<bool, std::string> genre() const
{
return { m_genre.has_value(), m_genre.value_or("") };
}
Expand Down
4 changes: 2 additions & 2 deletions src/help.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iomanip>
#include <string>

constexpr static const int VERSION = 100;
constexpr static int VERSION = 110;

inline void print_usage(std::ostream& stream, const std::string& exe_name)
{
Expand Down Expand Up @@ -39,7 +39,7 @@ inline void print_help(const std::string& exe_name)
<< " " << "[STR] - String type" << "\n"
<< " " << "[INT] - Integer type" << "\n"
<< "\n"
<< " " << "If no argument is specified, information of given file is retrieved." << "\n"
<< " " << "If no arguments are specified, information of given file is retrieved." << "\n"
<< " " << "If the option is not specified, the value is unchanged." << "\n"
<< " " << "If the argument is empty string (\"\") (for [STR]) or 0 (for [INT]) the value is cleared." << "\n"
<< "\n"
Expand Down
12 changes: 7 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void print_field(const std::string& field_name, const T& field_value)
std::cout << field_name << ": " << field_value << std::endl;
}

bool process_file(arguments&& args)
bool process_file(const arguments& args)
{
platform::string file_name = platform::convert::to_platform(args.file_name());
TagLib::FileRef file(file_name.c_str());
Expand All @@ -41,17 +41,19 @@ bool process_file(arguments&& args)

TagLib::Tag& tag = *file.tag();

/*
auto [artist_valid, artist] = args.artist();
auto [title_valid, title] = args.title();
auto [album_valid, album] = args.album();
auto [year_valid, year] = args.year();
auto [track_valid, track] = args.track();
auto [genre_valid, genre] = args.genre();
*/

auto utf8string = [](const std::string& str)
{
if (str.empty())
return TagLib::String::null;
return TagLib::String{};
return TagLib::String(str, TagLib::String::Type::UTF8);
};

Expand Down Expand Up @@ -86,8 +88,8 @@ bool process_file(arguments&& args)
return true;
}

constexpr static const int RETURN_OK = 0;
constexpr static const int RETURN_ERROR = 1;
constexpr static int RETURN_OK = 0;
constexpr static int RETURN_ERROR = 1;

int MAIN(int argc, platform::char_t* argv[])
{
Expand Down Expand Up @@ -117,7 +119,7 @@ int MAIN(int argc, platform::char_t* argv[])
return RETURN_OK;
}

if (!process_file(std::move(args.value())))
if (!process_file(args.value()))
{
std::cerr << "Couldn't process given file" << std::endl;
print_usage(std::cerr, exe_name);
Expand Down
4 changes: 1 addition & 3 deletions src/platform.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once
#include <string>
#include <vector>
#include <iostream>
#include <taglib/tstring.h>

#ifdef _MSC_VER
#define TAGLIB_HEADERS_BEGIN __pragma(warning(disable: 4251))
Expand All @@ -18,7 +16,6 @@

#ifdef _MSC_VER
#include <Windows.h>
#include <io.h>
#include <fcntl.h>
#define MAIN wmain
#else
Expand Down Expand Up @@ -54,6 +51,7 @@ namespace platform
static std::vector<std::string> convert_args(int argc, platform::char_t** argv)
{
std::vector<std::string> args;
args.reserve(argc);
for (int i = 0; i < argc; ++i)
args.push_back(from_platform(argv[i]));
return args;
Expand Down

0 comments on commit a4df286

Please sign in to comment.