This repository has been archived by the owner on Dec 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Book.cpp
144 lines (131 loc) · 4.53 KB
/
Book.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "Book.h"
#include "Chapter.h"
#include "Includes.h"
#include <regex>
#include <iostream>
#include <sstream>
#include <fstream>
#include "Preferences.h"
void Book::VolumeUpdate() {
delete Volumes;
Volumes = gcnew VTable(Volume::typeid);
cli::array<System::String^>^ dirs = System::IO::Directory::GetDirectories(Directory);
for (unsigned int idx = 0; idx < dirs->Length; idx++) {
Volume^ Vol = gcnew Volume();
Vol->ParseVolume(dirs[idx]);
this->Volumes->Add(idx, Vol);
delete Vol;
}
}
bool Book::Update()
{
char buffer[1024];
std::string stdPath;
sprintf_s(buffer, "%s\\Books\\%s\\%s", Preferences::GetBookDirectory().c_str(), msclr::interop::marshal_as<std::string>(this->Title->ToString()).c_str(), "000_b_Data.ktf");
stdPath = std::string(buffer);
stdPath.erase(std::remove(stdPath.begin(), stdPath.end(), '\r'), stdPath.end());
stdPath.erase(std::remove(stdPath.begin(), stdPath.end(), '?'), stdPath.end());
stdPath = std::regex_replace(stdPath, std::regex("^ +| +$|( ) +"), "$1");
std::ofstream L(stdPath.c_str());
L << msclr::interop::marshal_as<std::string>(this->Title->ToString()).c_str() << "\n";
L << msclr::interop::marshal_as<std::string>(this->Author->ToString()).c_str() << "\n";
L << msclr::interop::marshal_as<std::string>(this->numChapters.ToString()).c_str() << "\n";
L << msclr::interop::marshal_as<std::string>(this->CurrentChapter.ToString()).c_str() << "\n";
if (this->Summary != nullptr) {
L << "_SUMMARY_" << "\n";
L << msclr::interop::marshal_as<std::string>(this->Summary->ToString()).c_str() << "\n";
L << "_END_" << "\n";
}
L.close();
return false;
}
inline Book^ Book::Update(Book^ book)
{
char buffer[1024];
std::string stdPath;
sprintf_s(buffer, "%s\\Books\\%s\\%s", Preferences::GetBookDirectory().c_str(), msclr::interop::marshal_as<std::string>(book->Title->ToString()).c_str(), "000_b_Data.ktf");
stdPath = std::string(buffer);
stdPath.erase(std::remove(stdPath.begin(), stdPath.end(), '\r'), stdPath.end());
stdPath.erase(std::remove(stdPath.begin(), stdPath.end(), '?'), stdPath.end());
stdPath = std::regex_replace(stdPath, std::regex("^ +| +$|( ) +"), "$1");
std::ofstream L(stdPath.c_str());
L << msclr::interop::marshal_as<std::string>(book->Title->ToString()).c_str();
L << msclr::interop::marshal_as<std::string>(book->Author->ToString()).c_str();
L << msclr::interop::marshal_as<std::string>(book->numChapters.ToString()).c_str();
L << msclr::interop::marshal_as<std::string>(book->CurrentChapter.ToString()).c_str();
if (book->Summary != nullptr) {
L << "_SUMMARY_";
L << msclr::interop::marshal_as<std::string>(book->Summary->ToString()).c_str();
L << "_END_";
}
L.close();
return book;
}
Book^ Book::ParseBook(System::String^ bookfolder)
{
std::cout << msclr::interop::marshal_as<std::string>(bookfolder->ToString());
System::String^ Path = System::IO::Directory::GetFiles(bookfolder)[1];
System::Drawing::Bitmap^ cover = gcnew System::Drawing::Bitmap(System::Drawing::Bitmap::FromFile(Path));
//System::String^ title;
std::ifstream istream(msclr::interop::marshal_as<std::string>(System::IO::Directory::GetFiles(bookfolder)[0]->ToString()));
std::fstream fstream;
fstream.open(msclr::interop::marshal_as<std::string>(System::IO::Directory::GetFiles(bookfolder)[0]->ToString()), std::ios::in);
std::string a;
std::string aa;
int idx = 0;
std::stringstream buffer;
buffer << istream.rdbuf();
Book^ book = gcnew Book(nullptr, nullptr, nullptr, nullptr);
book->Directory = bookfolder;
while (std::getline(buffer, aa, '\r'))
{
switch (idx) {
case 0:
book->Title = msclr::interop::marshal_as<System::String^>(aa);
break;
case 1:
book->Author = msclr::interop::marshal_as<System::String^>(aa);
break;
case 2:
book->numChapters = std::atoi(aa.c_str());
break;
case 3:
book->CurrentChapter = std::atoi(aa.c_str());
break;
default:
break;
}
idx++;
}
book->Cover = cover;
return book;
}
Book::Book(System::Drawing::Bitmap^ cover, System::String^ title, System::String^ author, System::String^ lastUpdated)
{
Cover = cover;
Title = title;
Author = author;
UpdateTime = lastUpdated;
Chapters = gcnew VTable(Chapter::typeid);
Volumes = gcnew VTable(Volume::typeid);
}
Book::Book(const Book% book) {
Cover = book.Cover;
Title = book.Title;
Ranking = book.Ranking;
CurrentChapter = book.CurrentChapter;
Chapters = book.Chapters;
}
Book::~Book()
{
std::cout << "Deleting Book Object" << std::endl;
delete Cover;
delete Title;
delete Author;
delete Volumes;
delete UpdateTime;
ReadingTime = 0;
Ranking = 0;
CurrentChapter = 0;
delete Chapters;
}