ON_wString ON_wString::Mid(int i, int count) const { ON_wString(s); if ( i >= 0 && i < Length() && count > 0 ) { if ( count > Length() - i ) count = Length() - i; s.CopyToArray( count, &m_s[i] ); } return s; }
const ON_wString Internal_CleanPath(const wchar_t* dirty_path) const { const wchar_t* volume = 0; const wchar_t* path = 0; // Use local path in case drive, dir, file_name_stem or ext are being reused. on_wsplitpath(dirty_path, &volume, &path, nullptr, nullptr); ON_wString clean_path(path); if (clean_path.IsEmpty()) return ON_wString(dirty_path); clean_path.Replace(ON_wString::Backslash, ON_wString::Slash); if (nullptr != volume && volume < path) { ON_wString clean_volume(volume, (int)(path - volume)); return (clean_volume + clean_path); } return clean_path; }
const ON_wString Internal_CTestContext::TextLogPathFromFullPath(const wchar_t* full_path) const { // replace initial directory with <Initial Folder> and use / for // the directory separator so that output files are standardized. ON_wString text_log_path; ON_wString path1 = Internal_CleanPath(full_path); if (m_initial_directory_length > 0 && ON_wString::EqualOrdinal(m_initial_directory, m_initial_directory_length, path1, m_initial_directory_length, true) ) { text_log_path = (m_initial_directory_counter>0) ? ON_wString::FormatToString(L"<initial folder %u>", m_initial_directory_counter) : ON_wString(L"<initial folder>"); text_log_path += static_cast<const wchar_t*>(path1) + m_initial_directory_length; } else { text_log_path = path1; } return text_log_path; }
static const ONX_ErrorCounter Internal_TestReadFolder( ON_TextLog& text_log, const wchar_t* directory_path, unsigned int directory_tree_depth, bool bVerbose, Internal_CTestContext& test_context ) { ONX_ErrorCounter error_counter; error_counter.ClearLibraryErrors(); if (nullptr == directory_path || 0 == directory_path[0]) { text_log.Print(L"Empty directory name.\n"); } ON_FileIterator fit; if (false == fit.Initialize(directory_path)) { text_log.Print( L"Invalid directory name: %ls\n", directory_path ); error_counter.IncrementFailureCount(); return error_counter; } const ON_wString text_log_directory_name = (directory_tree_depth <= 1) ? ON_wString(directory_path) : test_context.TextLogPathFromFullPath(directory_path); text_log.Print( L"Directory name: %ls\n", static_cast<const wchar_t*>(text_log_directory_name) ); text_log.PushIndent(); ON_ClassArray< ON_wString > sub_directories(32); ON_ClassArray< ON_wString > skipped_files(32); ON_ClassArray< ON_wString > tested_files(32); for ( bool bHaveItem = fit.FirstItem(); bHaveItem; bHaveItem = fit.NextItem() ) { if ( test_context.m_max_file_count > 0 && test_context.m_file_count >= test_context.m_max_file_count) break; if (fit.CurrentItemIsDirectory()) { if (directory_tree_depth < test_context.m_max_directory_tree_depth) { sub_directories.Append(fit.CurrentItemFullPathName()); } continue; } ON_wString fullpath = fit.CurrentItemFullPathName(); if (ON_FileStream::Is3dmFile(fullpath, false)) tested_files.Append(fullpath); else skipped_files.Append(fullpath); } // sort file and folder names so test order depends only on content. // This is required so results from different computers can be compared. sub_directories.QuickSort(Internal_ComparePath); skipped_files.QuickSort(Internal_ComparePath); tested_files.QuickSort(Internal_ComparePath); if (skipped_files.Count() > 0) { text_log.PrintNewLine(); for (int i = 0; i < skipped_files.Count(); i++) { const ON_wString path_to_print = test_context.TextLogPathFromFullPath(skipped_files[i]); text_log.Print( L"Skipped file: %ls\n", static_cast<const wchar_t*>(path_to_print) ); } text_log.PrintNewLine(); } for ( int i = 0; i < tested_files.Count(); i++ ) { const ON_wString full_path = tested_files[i]; const ON_wString path_to_print = test_context.TextLogPathFromFullPath(full_path); test_context.m_file_count++; const ONX_ErrorCounter file_error_counter = Internal_TestFileRead(text_log, full_path, path_to_print, bVerbose); error_counter += file_error_counter; } for (int i = 0; i < sub_directories.Count(); i++) { if (test_context.m_max_file_count > 0 && test_context.m_file_count >= test_context.m_max_file_count) break; const ON_wString sub_directory_path = sub_directories[i]; test_context.m_directory_count++; error_counter += Internal_TestReadFolder(text_log, sub_directory_path, directory_tree_depth + 1, bVerbose, test_context); } text_log.PopIndent(); return error_counter; }