Hello all, I’ve got problem with reading binary files(exe) (visual studio 2022).
I want to read file into TextEditor component. When I choose txt file, everything is fine, content is read , every char changed into decimal representation and put into editor. When I try to make, the same thing with exe file, application freezes
I tried to create new_output_string with new operator, I tried to use char table with new, I tried to use fscanf() and getwc() and nothing. When I used Builder 6.0 before there was no problem.
The code is:
in main class are
class MainComponent : public juce::Component
{
public:
juce::TextButton open_button{"Open"};
juce::TextEditor texteditor;
MainComponent()
{
setSize (700, 500);
close_button.setBounds(0,0,200,50);
addAndMakeVisible(open_button);
text_editor.setBounds(0,60,500,350);
addAndMakeVisible(text_editor);
text_editor.setMultiLine(true,true);
open_button.onClick = [this](){
/*creating fileChooser component to select the file to be opened*/
fChooser = std::make_unique<juce::FileChooser>("Choose file",
defaultDirectory, "*.*", true, false, this);
auto folderChooserFlags = juce::FileBrowserComponent::openMode
| juce::FileBrowserComponent::canSelectDirectories |
juce::FileBrowserComponent::canSelectFiles;
/*launching fileChooser*/
fChooser->launchAsync(folderChooserFlags, [this](const juce::FileChooser& chooser)
{
juce::File chosenFile = chooser.getResult();
juce::String tmp_path= chosenFile.getFullPathName();
oldPath=tmp_path;
char file_path[555];
// temporary int to store the value from file stream and file pointers
int tmp_int;
FILE *file_1,*file_2;
strcpy(file_path,tmp_path.toRawUTF8());
juce::FileInputStream input_stream{chosenFile};
juce::int64 size_of_file;
juce::String new_tmp_string;
juce::String new_output_string="";
// getting size of the choosen file and changing it to string type
size_of_file=input_stream.getTotalLength();
juce::String str = juce::String(size_of_file);
// creating log file to make sure the file path and size of the file are correct
file_1=fopen("K:\\a.txt","w");
fprintf(file_1,"%s%s%s",file_path,",",str);
fclose(file_1);
file_2=fopen(file_path,"rb");
//reading binary content of the file , converting it into characters, spacing and
//creating brand new string that will be put into text editor
while(!feof(file_2)){
tmp_int=fgetc(file_2);
new_tmp_string=juce::String(tmp_int);
new_output_string+=new_tmp_string;
new_output_string+=" , ";}
fclose(file_2);
// setting content of text_editor component
text_editor.setText(new_output_string,true);
// setting text of button to see if size is correct
open_button.setButtonText(str);
//setting new path so at the next showing fileChooser it's path is the same
defaultDirectory=oldPath;
});
//..
}