Browse code

Fix porting mistake made during commit 1e52dd4b422b7815eb6902cdc0a80d7e49d05826

Clarissa Walker authored on 2024/08/22 22:10:27
Showing 1 changed files
... ...
@@ -40,7 +40,7 @@ protected:
40 40
 	bool hasFile;
41 41
 	std::vector<std::uint8_t> rawData, reservedSection, programSection;
42 42
 	TagList tags;
43
-	std::filesystem::path filePath; readTagsOnly = false);
43
+	std::filesystem::path filePath;
44 44
 	std::string FormattedTitleOptionalBlock(const std::string &block, bool &hadReplacement, unsigned level) const;
45 45
 public:
46 46
 	XSFFile();
Browse code

Port: Use std::filesystem::path for reading/writing files. - before override

Clarissa Walker authored on 2024/08/22 20:57:20
Showing 1 changed files
... ...
@@ -7,6 +7,7 @@
7 7
 
8 8
 #pragma once
9 9
 
10
+#include <filesystem>
10 11
 #include <fstream>
11 12
 #include <string>
12 13
 #include <vector>
... ...
@@ -31,26 +32,20 @@ enum class PeakType
31 32
 
32 33
 class XSFFile
33 34
 {
35
+private:
36
+	void ReadXSF(const std::filesystem::path &path, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
37
+	void ReadXSF(std::ifstream &xSF, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
34 38
 protected:
35 39
 	std::uint8_t xSFType;
36 40
 	bool hasFile;
37 41
 	std::vector<std::uint8_t> rawData, reservedSection, programSection;
38 42
 	TagList tags;
39
-	std::string fileName;
40
-	void ReadXSF(const std::string &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
41
-#ifdef _WIN32
42
-	void ReadXSF(const std::wstring &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
43
-#endif
44
-	void ReadXSF(std::ifstream &xSF, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
43
+	std::filesystem::path filePath; readTagsOnly = false);
45 44
 	std::string FormattedTitleOptionalBlock(const std::string &block, bool &hadReplacement, unsigned level) const;
46 45
 public:
47 46
 	XSFFile();
48
-	XSFFile(const std::string &filename);
49
-	XSFFile(const std::string &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize);
50
-#ifdef _WIN32
51
-	XSFFile(const std::wstring &filename);
52
-	XSFFile(const std::wstring &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize);
53
-#endif
47
+	XSFFile(const std::filesystem::path &path);
48
+	XSFFile(const std::filesystem::path &path, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize);
54 49
 	bool IsValidType(std::uint8_t type) const;
55 50
 	void Clear();
56 51
 	bool HasFile() const;
... ...
@@ -72,7 +67,7 @@ public:
72 67
 	unsigned long GetFadeMS(unsigned long defaultFade) const;
73 68
 	double GetVolume(VolumeType preferredVolumeType, PeakType preferredPeakType) const;
74 69
 	std::string GetFormattedTitle(const std::string &format) const;
75
-	std::string GetFilename() const;
76
-	std::string GetFilenameWithoutPath() const;
70
+	std::filesystem::path GetFilepath() const;
71
+	std::filesystem::path GetFilenameWithoutPath() const;
77 72
 	void SaveFile() const;
78 73
 };
Browse code

Various changes:

* Use enum class instead of enum (except for the enums for the resource IDs, not really necessary there).
* For NCSF specifically, included a function to convert an enum class to its underlying integral type (as this is needed for use with the std::bitset class).
* Cleanup headers so all the ones needed in a file are explicitly included even if they may possibly be included in another header.
* Used forward declarations in a few spots.
* Explicitly namespaced all (u)int*_t uses (this might seem like overkill, but it helps me see when the standard types are being used with a simple search for std::).
* Made sure it all builds with MinGW-w64 as well (both gcc and clang).
* Removed some std::move from DialogBuilder.cpp based on clang's warnings for that.
* Replaced use of std::copy_n on strings in DialogBuilder.cpp with my CopyToString functions that use wcscpy.
* Replaced CHAR_MIN/CHAR_MAX in eqstr.h and ltstr.h with std::numeric_limits<char>::min/max().

Naram Qashat authored on 2021/03/21 03:16:45
Showing 1 changed files
... ...
@@ -7,54 +7,57 @@
7 7
 
8 8
 #pragma once
9 9
 
10
+#include <fstream>
11
+#include <string>
12
+#include <vector>
10 13
 #include <cstdint>
11 14
 #include "convert.h"
12 15
 #include "TagList.h"
13 16
 
14
-enum VolumeType
17
+enum class VolumeType
15 18
 {
16
-	VOLUMETYPE_NONE,
17
-	VOLUMETYPE_VOLUME,
18
-	VOLUMETYPE_REPLAYGAIN_TRACK,
19
-	VOLUMETYPE_REPLAYGAIN_ALBUM
19
+	None,
20
+	Volume,
21
+	ReplayGainTrack,
22
+	ReplayGainAlbum
20 23
 };
21 24
 
22
-enum PeakType
25
+enum class PeakType
23 26
 {
24
-	PEAKTYPE_NONE,
25
-	PEAKTYPE_REPLAYGAIN_TRACK,
26
-	PEAKTYPE_REPLAYGAIN_ALBUM
27
+	None,
28
+	ReplayGainTrack,
29
+	ReplayGainAlbum
27 30
 };
28 31
 
29 32
 class XSFFile
30 33
 {
31 34
 protected:
32
-	uint8_t xSFType;
35
+	std::uint8_t xSFType;
33 36
 	bool hasFile;
34
-	std::vector<uint8_t> rawData, reservedSection, programSection;
37
+	std::vector<std::uint8_t> rawData, reservedSection, programSection;
35 38
 	TagList tags;
36 39
 	std::string fileName;
37
-	void ReadXSF(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
40
+	void ReadXSF(const std::string &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
38 41
 #ifdef _WIN32
39
-	void ReadXSF(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
42
+	void ReadXSF(const std::wstring &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
40 43
 #endif
41
-	void ReadXSF(std::ifstream &xSF, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
44
+	void ReadXSF(std::ifstream &xSF, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize, bool readTagsOnly = false);
42 45
 	std::string FormattedTitleOptionalBlock(const std::string &block, bool &hadReplacement, unsigned level) const;
43 46
 public:
44 47
 	XSFFile();
45 48
 	XSFFile(const std::string &filename);
46
-	XSFFile(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
49
+	XSFFile(const std::string &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize);
47 50
 #ifdef _WIN32
48 51
 	XSFFile(const std::wstring &filename);
49
-	XSFFile(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
52
+	XSFFile(const std::wstring &filename, std::uint32_t programSizeOffset, std::uint32_t programHeaderSize);
50 53
 #endif
51
-	bool IsValidType(uint8_t type) const;
54
+	bool IsValidType(std::uint8_t type) const;
52 55
 	void Clear();
53 56
 	bool HasFile() const;
54
-	std::vector<uint8_t> &GetReservedSection();
55
-	std::vector<uint8_t> GetReservedSection() const;
56
-	std::vector<uint8_t> &GetProgramSection();
57
-	std::vector<uint8_t> GetProgramSection() const;
57
+	std::vector<std::uint8_t> &GetReservedSection();
58
+	std::vector<std::uint8_t> GetReservedSection() const;
59
+	std::vector<std::uint8_t> &GetProgramSection();
60
+	std::vector<std::uint8_t> GetProgramSection() const;
58 61
 	const TagList &GetAllTags() const;
59 62
 	void SetAllTags(const TagList &newTags);
60 63
 	void SetTag(const std::string &name, const std::string &value);
Browse code

Some conversion replacements:

* Replace the (w)stringify functions with the standard std::to_(w)string functions.
* Replace convertTo with versions that use type_traits to determine which standard string conversion function to call, as well as handle enums specically.

Naram Qashat authored on 2021/03/19 11:57:21
Showing 1 changed files
... ...
@@ -63,7 +63,7 @@ public:
63 63
 	std::string GetTagValue(const std::string &name) const;
64 64
 	template<typename T> T GetTagValue(const std::string &name, const T &defaultValue) const
65 65
 	{
66
-		return this->GetTagExists(name) ? convertTo<T>(this->GetTagValue(name), false) : defaultValue;
66
+		return this->GetTagExists(name) ? convertTo<T>(this->GetTagValue(name)) : defaultValue;
67 67
 	}
68 68
 	unsigned long GetLengthMS(unsigned long defaultLength) const;
69 69
 	unsigned long GetFadeMS(unsigned long defaultFade) const;
Browse code

Remove last modification date from files.

(I never remember to update these and besides, GitHub history can show when they were last modified.)

Naram Qashat authored on 2021/03/19 10:58:12
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 /*
2 2
  * xSF - File structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-24
5 4
  *
6 5
  * Partially based on the vio*sf framework
7 6
  */
Browse code

Lots of changes in regards to strings, as follows:

* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.

Naram Qashat authored on 2014/09/24 13:58:55
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - File structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-17
4
+ * Last modification on 2014-09-24
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -11,7 +11,6 @@
11 11
 #include <cstdint>
12 12
 #include "convert.h"
13 13
 #include "TagList.h"
14
-#include "BigSString.h"
15 14
 
16 15
 enum VolumeType
17 16
 {
... ...
@@ -35,18 +34,18 @@ protected:
35 34
 	bool hasFile;
36 35
 	std::vector<uint8_t> rawData, reservedSection, programSection;
37 36
 	TagList tags;
38
-	String fileName;
37
+	std::string fileName;
39 38
 	void ReadXSF(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
40
-#ifdef _MSC_VER
39
+#ifdef _WIN32
41 40
 	void ReadXSF(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
42 41
 #endif
43 42
 	void ReadXSF(std::ifstream &xSF, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
44
-	String FormattedTitleOptionalBlock(const std::wstring &block, bool &hadReplacement, unsigned level) const;
43
+	std::string FormattedTitleOptionalBlock(const std::string &block, bool &hadReplacement, unsigned level) const;
45 44
 public:
46 45
 	XSFFile();
47 46
 	XSFFile(const std::string &filename);
48 47
 	XSFFile(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
49
-#ifdef _MSC_VER
48
+#ifdef _WIN32
50 49
 	XSFFile(const std::wstring &filename);
51 50
 	XSFFile(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
52 51
 #endif
... ...
@@ -59,18 +58,19 @@ public:
59 58
 	std::vector<uint8_t> GetProgramSection() const;
60 59
 	const TagList &GetAllTags() const;
61 60
 	void SetAllTags(const TagList &newTags);
62
-	void SetTag(const std::string &name, const String &value);
61
+	void SetTag(const std::string &name, const std::string &value);
62
+	void SetTag(const std::string &name, const std::wstring &value);
63 63
 	bool GetTagExists(const std::string &name) const;
64
-	String GetTagValue(const std::string &name) const;
64
+	std::string GetTagValue(const std::string &name) const;
65 65
 	template<typename T> T GetTagValue(const std::string &name, const T &defaultValue) const
66 66
 	{
67
-		return this->GetTagExists(name) ? convertTo<T>(this->GetTagValue(name).GetAnsi(), false) : defaultValue;
67
+		return this->GetTagExists(name) ? convertTo<T>(this->GetTagValue(name), false) : defaultValue;
68 68
 	}
69 69
 	unsigned long GetLengthMS(unsigned long defaultLength) const;
70 70
 	unsigned long GetFadeMS(unsigned long defaultFade) const;
71 71
 	double GetVolume(VolumeType preferredVolumeType, PeakType preferredPeakType) const;
72
-	String GetFormattedTitle(const std::wstring &format) const;
73
-	String GetFilename() const;
74
-	String GetFilenameWithoutPath() const;
72
+	std::string GetFormattedTitle(const std::string &format) const;
73
+	std::string GetFilename() const;
74
+	std::string GetFilenameWithoutPath() const;
75 75
 	void SaveFile() const;
76 76
 };
Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - File structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-08
4
+ * Last modification on 2014-09-17
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -9,6 +9,7 @@
9 9
 #pragma once
10 10
 
11 11
 #include <cstdint>
12
+#include "convert.h"
12 13
 #include "TagList.h"
13 14
 #include "BigSString.h"
14 15
 
... ...
@@ -36,7 +37,7 @@ protected:
36 37
 	TagList tags;
37 38
 	String fileName;
38 39
 	void ReadXSF(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
39
-#ifdef _WIN32
40
+#ifdef _MSC_VER
40 41
 	void ReadXSF(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
41 42
 #endif
42 43
 	void ReadXSF(std::ifstream &xSF, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
... ...
@@ -45,7 +46,7 @@ public:
45 46
 	XSFFile();
46 47
 	XSFFile(const std::string &filename);
47 48
 	XSFFile(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
48
-#ifdef _WIN32
49
+#ifdef _MSC_VER
49 50
 	XSFFile(const std::wstring &filename);
50 51
 	XSFFile(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
51 52
 #endif
Browse code

Use #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:47:36
Showing 1 changed files
... ...
@@ -1,13 +1,12 @@
1 1
 /*
2 2
  * xSF - File structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-23
4
+ * Last modification on 2014-09-08
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
8 8
 
9
-#ifndef XSFFILE_H
10
-#define XSFFILE_H
9
+#pragma once
11 10
 
12 11
 #include <cstdint>
13 12
 #include "TagList.h"
... ...
@@ -74,5 +73,3 @@ public:
74 73
 	String GetFilenameWithoutPath() const;
75 74
 	void SaveFile() const;
76 75
 };
77
-
78
-#endif
Browse code

Added Lanczos interpolation to the NCSF plugin, and cleaned up a bit of the other code, as well as removing pstdint.h since it's no longer needed.

Naram Qashat authored on 2013/04/23 20:29:21
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - File structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-21
4
+ * Last modification on 2013-04-23
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -9,9 +9,9 @@
9 9
 #ifndef XSFFILE_H
10 10
 #define XSFFILE_H
11 11
 
12
+#include <cstdint>
12 13
 #include "TagList.h"
13 14
 #include "BigSString.h"
14
-#include "pstdint.h"
15 15
 
16 16
 enum VolumeType
17 17
 {
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,78 @@
1
+/*
2
+ * xSF - File structure
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-21
5
+ *
6
+ * Partially based on the vio*sf framework
7
+ */
8
+
9
+#ifndef XSFFILE_H
10
+#define XSFFILE_H
11
+
12
+#include "TagList.h"
13
+#include "BigSString.h"
14
+#include "pstdint.h"
15
+
16
+enum VolumeType
17
+{
18
+	VOLUMETYPE_NONE,
19
+	VOLUMETYPE_VOLUME,
20
+	VOLUMETYPE_REPLAYGAIN_TRACK,
21
+	VOLUMETYPE_REPLAYGAIN_ALBUM
22
+};
23
+
24
+enum PeakType
25
+{
26
+	PEAKTYPE_NONE,
27
+	PEAKTYPE_REPLAYGAIN_TRACK,
28
+	PEAKTYPE_REPLAYGAIN_ALBUM
29
+};
30
+
31
+class XSFFile
32
+{
33
+protected:
34
+	uint8_t xSFType;
35
+	bool hasFile;
36
+	std::vector<uint8_t> rawData, reservedSection, programSection;
37
+	TagList tags;
38
+	String fileName;
39
+	void ReadXSF(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
40
+#ifdef _WIN32
41
+	void ReadXSF(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
42
+#endif
43
+	void ReadXSF(std::ifstream &xSF, uint32_t programSizeOffset, uint32_t programHeaderSize, bool readTagsOnly = false);
44
+	String FormattedTitleOptionalBlock(const std::wstring &block, bool &hadReplacement, unsigned level) const;
45
+public:
46
+	XSFFile();
47
+	XSFFile(const std::string &filename);
48
+	XSFFile(const std::string &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
49
+#ifdef _WIN32
50
+	XSFFile(const std::wstring &filename);
51
+	XSFFile(const std::wstring &filename, uint32_t programSizeOffset, uint32_t programHeaderSize);
52
+#endif
53
+	bool IsValidType(uint8_t type) const;
54
+	void Clear();
55
+	bool HasFile() const;
56
+	std::vector<uint8_t> &GetReservedSection();
57
+	std::vector<uint8_t> GetReservedSection() const;
58
+	std::vector<uint8_t> &GetProgramSection();
59
+	std::vector<uint8_t> GetProgramSection() const;
60
+	const TagList &GetAllTags() const;
61
+	void SetAllTags(const TagList &newTags);
62
+	void SetTag(const std::string &name, const String &value);
63
+	bool GetTagExists(const std::string &name) const;
64
+	String GetTagValue(const std::string &name) const;
65
+	template<typename T> T GetTagValue(const std::string &name, const T &defaultValue) const
66
+	{
67
+		return this->GetTagExists(name) ? convertTo<T>(this->GetTagValue(name).GetAnsi(), false) : defaultValue;
68
+	}
69
+	unsigned long GetLengthMS(unsigned long defaultLength) const;
70
+	unsigned long GetFadeMS(unsigned long defaultFade) const;
71
+	double GetVolume(VolumeType preferredVolumeType, PeakType preferredPeakType) const;
72
+	String GetFormattedTitle(const std::wstring &format) const;
73
+	String GetFilename() const;
74
+	String GetFilenameWithoutPath() const;
75
+	void SaveFile() const;
76
+};
77
+
78
+#endif