-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecri.cpp
More file actions
253 lines (173 loc) · 4.25 KB
/
Copy pathrecri.cpp
File metadata and controls
253 lines (173 loc) · 4.25 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <memory>
#include <filesystem>
#include <chrono>
#include <thread>
#include <stdexcept>
#include <sstream>
/*
* BIG TODOS:
* process files
* versioning each thing of whatever it sees
* etc
*/
const std::string idealfilextension = ".bitt";
std::vector<std::string> tokenstants = {":",";","@@"};
struct registers{
std::string containt;
std::string mitsage;
std::string nominem;
};
auto mod1(std::filesystem::path k ){
std::string roi ="";
std::ifstream yo(k);
if (!yo.is_open()) return roi;
size_t po =0;
size_t m =0;
std::stringstream yocast;
yocast << yo.rdbuf();
yo.close();
std::string palius = yocast.str();
/* auto camito =[&]()->int{
for(size_t i =0; i<palius.length(); i++){
if(tokenstants[0] == palius[i]){
m =i;
for(size_t op=m+1; op<palius.length(); op++){
if(palius[op] ==tokenstants[1])
break;
roi += palius[op];
}
break;
}
}
return std::stoi(roi);
}; */
auto camito = [&]() -> int {
auto initius = palius.find(tokenstants[0]); // ":"
auto end = palius.find(tokenstants[1]); // ";"
if (initius == std::string::npos ||
end == std::string::npos ||
end <= initius + 1) {
throw std::runtime_error("Formato de version invalido");
}
std::string roi = palius.substr(initius + 1,end - initius - 1);
return std::stoi(roi);
};
int replacer =camito();
int tojmi = replacer;
replacer++;
int f =0;
int roe =0;
auto s = std::to_string(replacer);
auto krosi = std::to_string(tojmi);
auto pancho = [&]()->std::string{
std::string alt = "version:"+krosi+";";
std::string neu = "version:"+s+";";
auto kairmos = palius.find(alt);
if(kairmos!= std::string::npos){
palius.replace(kairmos,alt.length(),neu);
}
return palius;
};
std::string text_finale = pancho();
std::string final;
std::ofstream archivo_out(k, std::ios::trunc);
if (archivo_out.is_open()) {
archivo_out << text_finale;
final = text_finale;
}
archivo_out.close();
return final;
}
void creador(registers& r){
/*
* function related to create a file if this one doesn't exist
*/
r.mitsage = "version:0; //This file is generated by the program @@";
r.nominem = "register.bitt";
std::ofstream archivo(r.nominem,std::ios::trunc);
archivo<<r.mitsage;
}
auto filebuscador(std::filesystem::path routedrats){
int contador = 0;
for(const auto& bit : std::filesystem::directory_iterator(routedrats)){
if(bit.is_regular_file() &&
bit.path().extension() == idealfilextension){
contador++;
}
}
//std::cout<<contador; debug only*****
if( 2<=contador){
return 1;
}
else{
return 0;
}
}
auto zoek(std::filesystem::path rutilla){
for(const auto& interada :
std::filesystem::directory_iterator(rutilla)){
if(interada.is_regular_file()){
if(interada.path()
.filename() == "register.bitt"){
return interada.path();
}
}
}
return std::filesystem::path {};
}
int main(int argc, char*argv[]){
registers k;
std::string data{};
std::stringstream insert{};
std::filesystem::path aqui = std::filesystem::current_path();
auto bit =filebuscador(aqui);
if(bit ==1){
std::cerr<<"liado parda\n";
return 1;
}
else{
}
auto ko = zoek(aqui);
if(ko.empty()){
creador(k);
ko = k.nominem;
}
else{
ko = zoek(aqui);
}
auto rwt =mod1(ko);
if(argc >=2 && bit ==0){
std::filesystem::path k=".";
for (const auto& entry : std::filesystem::directory_iterator(k)){
if(entry.path().filename().string()==argv[1]){
std::ifstream deif( entry.path());
insert<<deif.rdbuf();
data = insert.str();
size_t pos = rwt.find(tokenstants[2]);
if(pos != std::string::npos){
auto x = rwt + " " + data;
rwt = x;
std::ofstream out(ko, std::ios::trunc);
out << rwt;
}
else{
std::cerr<<"no anda bien aqui";
}
}
}
}
//for(const auto& attempt: std::filesystem::directory_iterator(k)){
//if(attempt.path().extension() == idealfilextension){
//std::stringrstream r{};
//r<<attempt.path();
//}
//TODO: TRY CATCH HERE
//else{
// std::cerr<<"algo ha fallado\n";
//}
return 0;
}