-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kabuk.cpp
123 lines (100 loc) · 3.19 KB
/
Kabuk.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
//
// Created by lutfullah on 13.06.2022.
//
#include "Kabuk.h"
#include "Bilimum.h"
void Kabuk::cd(vector<string> &arglar) {
Dizin cdDizini(suAnkiDizin);
if (cdDizini.git(arglar[1])) {
if (Dizin::klasordur(cdDizini.dizin)) {
suAnkiDizin = cdDizini;
}
}
}
/**
* @param arglar:
* ls
* ls path
* ls -l
* ls -l path
*/
void Kabuk::ls(std::vector<string> &arglar) {
string *yol = nullptr;
bool ayrintili = false;
if (arglar.size() > 1) {
if (arglar[1] == "-l") {
ayrintili = true;
} else {
yol = &arglar[1];
}
if (arglar.size() == 3) {
yol = &arglar[2];
}
}
Dizin listelemeDizini(suAnkiDizin);
if (yol) {
if (!listelemeDizini.git(*yol)) {
return;
}
}
listelemeDizini.ls(ayrintili);
}
void Kabuk::mkdir(std::vector<string> &arglar) {
dosyaOlustur(arglar, true);
}
void Kabuk::touch(std::vector<string> &arglar) {
dosyaOlustur(arglar, false);
}
void Kabuk::dosyaOlustur(vector<string> &arglar, bool klasordur) {
auto listelemeDizini = Dizin(suAnkiDizin);
vector<string> gidilecekDizinKelimeleri = ayir(arglar[1], '/');
string dizinAdi = gidilecekDizinKelimeleri.back();
gidilecekDizinKelimeleri.pop_back();
if (listelemeDizini.git(gidilecekDizinKelimeleri)) {
if (!listelemeDizini.git(dizinAdi)) { // zaten varmis.
listelemeDizini.dosyaOlustur(dizinAdi, klasordur);
}
}
}
void Kabuk::mv(std::vector<string> &arglar) {
Dizin kaynakDizinAnnesi(suAnkiDizin);
Dizin hedefDizin(suAnkiDizin);
if (arglar.size() != 3 || !hedefDizin.git(arglar[2])) {
return;
}
vector<string> kaynakDizinKelimeleri = ayir(arglar[1], '/');
string kaynakDizinAdi = kaynakDizinKelimeleri.back();
kaynakDizinKelimeleri.pop_back();
if (kaynakDizinAnnesi.git(kaynakDizinKelimeleri)) {
Dizin kaynakDizin(kaynakDizinAnnesi);
if (kaynakDizin.git(kaynakDizinAdi) && !kaynakDizin.kokDizindir() && kaynakDizin != suAnkiDizin) {
if (kaynakDizinAnnesi.fatFileEntrySil(kaynakDizinAdi)) {
hedefDizin.dizinEntrileriEkle(kaynakDizin.dizin);
auto anaID = hedefDizin.dizinClusterID;
hedefDizin.git(kaynakDizinAdi);
FatFile83 noktaNokta = sisko32.diskEntriOku(sisko32.clusterBaytAdresi(hedefDizin.dizinClusterID) + sizeof(FatFile83)).msdos;
noktaNokta.firstCluster = anaID & 0x0000FFFF;
noktaNokta.eaIndex = anaID >> 16;
sisko32.diskEntriYaz(sisko32.clusterBaytAdresi(hedefDizin.dizinClusterID) + sizeof(FatFile83), (FatFileEntry*)&noktaNokta);
}
}
}
}
void Kabuk::cat(std::vector<string> &arglar) {
auto okunacakDizin = Dizin(&sisko32);
if (okunacakDizin.git(arglar[1])) {
okunacakDizin.cat();
}
}
Kabuk::Kabuk(SISKO32 *sisko32Ptr) : sisko32(*sisko32Ptr), suAnkiDizin(sisko32Ptr) {
}
void Kabuk::promptYaz() {
if (suAnkiDizin.dizinKelimeleri.empty()) {
cout << "/> ";
} else {
for (auto &kelime: suAnkiDizin.dizinKelimeleri) {
cout << "/" << kelime;
}
cout << "> ";
}
}