//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// Reads checklist from file encoded in UTF-8. /// /// @retval true data loaded /// @retval false data load error /// static bool LoadUtfChecklist(const TCHAR* fileName, bool warn) { Utf8File file; if (!file.Open(fileName, Utf8File::io_read)) { if (warn) StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE); return(false); } #if TESTBENCH StartupStore(_T(". Loading UTF notes <%s>%s"),fileName,NEWLINE); #endif TCHAR TempString[MAXNOTETITLE]; TCHAR Details[MAXNOTEDETAILS+1]; TCHAR Name[MAXNOTETITLE+1]; bool inDetails = false; Details[0]= 0; Name[0]= 0; TempString[0]=0; bool firstline=true; while (file.ReadLn(TempString, MAXNOTETITLE)) { // skip comment lines if (TempString[0] == _T('#')) { firstline=false; continue; } // Skip BOMs, if existing. Just to be sure, we only check the very first line of the file. // UTF8 BOM: 0xef 0xbb 0xbf // Unicode l.e. BOM: 0xff 0xfe (not supported) // Unicode b.e. BOM: 0xfe 0xff (not supported) if (firstline && (byte)TempString[0]==0xef && (byte)TempString[1]==0xbb && (byte)TempString[2]==0xbf) { #ifdef TESTBENCH StartupStore(_T("... LoadUtfChecklist, ignoring UTF8 BOM%s\n"),NEWLINE); #endif AddChecklistLine(&TempString[3], Details, Name, inDetails); } else { if (firstline && ((unsigned)TempString[0]==0xffef || (unsigned)TempString[0]==0xfeff)) { #ifdef TESTBENCH StartupStore(_T("... LoadUtfChecklist, ignoring UNICODE BOM%s\n"),NEWLINE); #endif AddChecklistLine(&TempString[1], Details, Name, inDetails); } else { AddChecklistLine(TempString, Details, Name, inDetails); } } firstline=false; } // while if (inDetails) { _tcscat(Details,TEXT(ENDOFLINE)); addChecklist(Name, Details); } return(true); } // LoadUtfChecklist
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// Reads checklist from file encoded in UTF-8. /// /// @retval true data loaded /// @retval false data load error /// static bool LoadUtfChecklist(const TCHAR* fileName) { Utf8File file; if (!file.Open(fileName, Utf8File::io_read)) { StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE); return(false); } #if TESTBENCH StartupStore(_T(". Loading notes <%s>%s"),fileName,NEWLINE); #endif TCHAR TempString[MAXNOTETITLE]; TCHAR Details[MAXNOTEDETAILS+1]; TCHAR Name[MAXNOTETITLE+1]; bool inDetails = false; Details[0]= 0; Name[0]= 0; TempString[0]=0; while (file.ReadLn(TempString, MAXNOTETITLE)) { // skip comment lines if (TempString[0] == _T('#')) continue; AddChecklistLine(TempString, Details, Name, inDetails); } // while if (inDetails) { _tcscat(Details,TEXT("\r\n")); addChecklist(Name, Details); } return(true); } // LoadUtfChecklist
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// Reads checklist from file encoded in system code page. /// /// @retval true data loaded /// @retval false data load error /// static bool LoadAsciiChecklist(const TCHAR* fileName) { FILE * stream = _tfopen(fileName, _T("rt")); if(!stream) { StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE); return(false); } #if TESTBENCH StartupStore(_T(". Loading Ascii notes <%s>%s"),fileName,NEWLINE); #endif TCHAR TempString[MAXNOTEDETAILS+1]; TCHAR Details[MAXNOTEDETAILS+1]; TCHAR Name[MAXNOTETITLE+1]; bool inDetails = false; Details[0]= 0; Name[0]= 0; TempString[0]=0; charset cs = charset::unknown; while (ReadStringX(stream, MAXNOTETITLE, TempString, cs)) { /* size_t len = _tcslen(TempString); if (len > 0) { if (TempString[len - 1] == '\r') { TempString[len - 1]= 0; len--; } } // On PNA we may have TWO trailing CR if (len > 0) { if (TempString[len - 1] == '\r') { TempString[len - 1]= 0; } } */ AddChecklistLine(TempString, Details, Name, inDetails); } // while if (inDetails) { _tcscat(Details,TEXT(ENDOFLINE)); addChecklist(Name, Details); } fclose(stream); return(true); } // LoadAsciiChecklist
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// Reads checklist from file encoded in system code page. /// /// @retval true data loaded /// @retval false data load error /// static bool LoadAsciiChecklist(const TCHAR* fileName) { HANDLE hChecklist = CreateFile( fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( hChecklist == INVALID_HANDLE_VALUE) { StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE); return(false); } #if TESTBENCH StartupStore(_T(". Loading notes <%s>%s"),fileName,NEWLINE); #endif TCHAR TempString[MAXNOTETITLE+1]; TCHAR Details[MAXNOTEDETAILS+1]; TCHAR Name[MAXNOTETITLE+1]; bool inDetails = false; Details[0]= 0; Name[0]= 0; TempString[0]=0; while (ReadString(hChecklist, MAXNOTETITLE, TempString)) { size_t len = _tcslen(TempString); if (len > 0) { if (TempString[len - 1] == '\r') { TempString[len - 1]= 0; len--; } } // On PNA we may have TWO trailing CR if (len > 0) { if (TempString[len - 1] == '\r') { TempString[len - 1]= 0; } } AddChecklistLine(TempString, Details, Name, inDetails); } // while if (inDetails) { wcscat(Details,TEXT("\r\n")); addChecklist(Name, Details); } CloseHandle(hChecklist); return(true); } // LoadAsciiChecklist