-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLink2.cpp
97 lines (89 loc) · 2.45 KB
/
Link2.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
#include <iostream>
#include <fstream>
#include <windows.h>
#include <algorithm>
#include <vector>
#include <time.h>
using namespace std;
string dir = "DP.txt";
fstream archivo;
void abrir(string funcion){
archivo.open(dir, ios::in | ios::app);
for(int i = 0; archivo.fail() and i == 0; i++){
cout << "No se pudo abrir en " << funcion << "... reintentando" << endl;
archivo.close();
archivo.open(dir, ios::in | ios::app);
if(archivo.is_open()){cout << "error solucionado en " << funcion << endl;}
}
}
int tamano(){
abrir("tam");
int tam = count(istreambuf_iterator<char>(archivo), istreambuf_iterator<char>(), '\n');
archivo.close();
return tam;
}
void lectura() {
string linea_texto;
int tam = tamano();
abrir("lectura");
for (int cont = 1; cont <= tam; cont++) {
getline(archivo, linea_texto);
if (linea_texto != "") {
cout << cont << ". " << linea_texto << endl;
}
}
archivo.close();
}
void agregar(string str) {
string http = "https://", key = "&pkey=";
abrir("agregar");
string::size_type i = str.find(key);
if (i != string::npos){str.erase(i, key.length() + str.length());}
i = str.find(http);
if (i != string::npos){str.erase(i, http.length());}
archivo << str << "\n";
cout << "agregada" << endl;
archivo.close();
}
string IrLinea(int num) {
abrir("IrLinea");
string n_linea;
for (int i = 1; i < num; i++) {
archivo.ignore(numeric_limits<streamsize>::max(), '\n');
}
getline(archivo, n_linea);
archivo.close();
cout << num << ". " << n_linea << endl;
return n_linea;
}
void abrir_x_links(int pestanas){
int tam = tamano();
if (pestanas > tam){pestanas = tam;}
srand(time(NULL));
vector<int> elegidas;
int random;
for (int index = 0; index < pestanas; index++) {
random = rand()%tam + 1;
if (find(elegidas.begin(), elegidas.end(), random) != elegidas.end()) {
index--;
} else {
elegidas.push_back(random);
ShellExecute(NULL, "open", "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge - Acceso directo",\
IrLinea(random).c_str(), NULL, SW_SHOWDEFAULT);
}
}
}
int main() {
string str;
while (true) {
cout << "agg 1.read x.open" << endl;
cin >> str;
try{
int num = stoi(str);
if (num == 1){lectura();}
else{abrir_x_links(num);}
}catch(...){
agregar(str);
}
}
}