MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / LoadFile

Function LoadFile

Applications/TextEdit/main.cpp:25–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23std::string openPath;
24
25void LoadFile(const char* path){
26 textBox->contents.clear();
27
28 FILE* textFile = fopen(path, "r");
29
30 if(!textFile){
31 Lemon::GUI::DisplayMessageBox("Text Editor", "Failed to open file!", Lemon::GUI::MsgButtonsOK);
32 return;
33 }
34
35 fseek(textFile, 0, SEEK_END);
36 long textFileSize = ftell(textFile);
37 fseek(textFile, 0, SEEK_SET);
38
39 char* textBuffer = (char*)malloc(textFileSize + 1);
40
41 fread(textBuffer, textFileSize, 1, textFile);
42 for(int i = 0; i < textFileSize; i++){ if(textBuffer[i] == 0) textBuffer[i] = ' ';}
43 textBuffer[textFileSize] = 0;
44
45 textBox->LoadText(textBuffer);
46
47 free(textBuffer);
48
49 openPath = path;
50
51 char title[32 + openPath.length()];
52 sprintf(title, "Text Editor: %s", openPath.c_str());
53
54 window->SetTitle(title);
55}
56
57void SaveFile(const char* path){
58 struct stat sResult;

Callers 2

OpenFileFunction · 0.85
mainFunction · 0.85

Calls 5

DisplayMessageBoxFunction · 0.85
LoadTextMethod · 0.80
lengthMethod · 0.80
clearMethod · 0.45
SetTitleMethod · 0.45

Tested by

no test coverage detected