// Class automatically generated by Dev-C++ New Class wizard

#include "txt.h" // class's header file

// class constructor
txt::txt()
{
	// insert your code here
	sdrawer = "ram:";
	sfilename = "empty.txt";
}

// class destructor
txt::~txt()
{
	// insert your code here
}

// get the filename and loads the textfile. Text content is store in stext 
void txt::LoadFile(char * drawer, char * file)
{
	/* TODO (#1#): Implement txt::LoadFile() */
 
  stext = "";
  sbuffer = "";	
  char * test;  
	
                                    sdrawer = drawer;
                                    iPosDrawer = sdrawer.find( ':', 0 );
                                               
                                               if(iPosDrawer < (sdrawer.length()-1))
                                               {
                                               sdrawer = sdrawer + "/";
                                               }
                                               
                                    sfilename = file;
                                    spath = sdrawer + sfilename;
                                                                           
                                    fdat_in.open(spath.c_str(), std::ios_base::in|std::ios::binary);
                                                              
                                    
                                    while (std::getline(fdat_in,sbuffer)) 
                                    {
                                           
                                                 if ( std::string::npos != sbuffer.find( '\r', 0 ))                             
                                                 {
                                                 stext = stext + sbuffer;
                                                 }
                                                 else
                                                 {
                                                 stext = stext + sbuffer + "\r";
                                                 }
                                          
                                          
                                    }
                                    fdat_in.close();
                                    fdat_in.clear();
                                    
                                    
}

// saves the Text in an textfile
void txt::SaveFile(char * drawer, char * file)
{
	/* TODO (#1#): Implement txt::SaveFile() */
                                    sdrawer = drawer;
                                    
                                    iPosDrawer = sdrawer.find_first_of( ':', 0 );
                                               
                                               if(iPosDrawer < (sdrawer.length()-1))
                                               {
                                               sdrawer = sdrawer + "/";
                                               }                                              
                                    
                                    sfilename = file;
                                    spath = sdrawer + sfilename;
	                                
                                    fdat_out.open(spath.c_str(), std::ios_base::out);
                                    fdat_out << stextbuffer.c_str() << std::endl;
                                    fdat_out.close();
                                    fdat_out.clear();
}                                   

// No description
void txt::Get_Text(char * text)
{
	/* TODO (#1#): Implement txt::Get_Text() */
	
	stextbuffer = text;
}
