o Replaced WIN32 directory scanner with dirent_win.h
authorjhurst <jhurst@cinecert.com>
Fri, 2 Dec 2016 18:45:14 +0000 (18:45 +0000)
committerjhurst <>
Fri, 2 Dec 2016 18:45:14 +0000 (18:45 +0000)
 o The NamespaceURI property of AS-02 timed text files has been exposed in the API
   and via as-02-wrap -P. This behavior replaces previous bad behavior, but puts
   responsibility for selecting the correct value on the operator.
 o Exposed CreatePNGNameId and CreateFontNameId subroutines in AS_02::TimedText
 o Adjusted UUID generation based on PNG and font names to exclude paths by
   inserting a call to PathBasename at each Id generation site

src/AS_02.h
src/KM_fileio.cpp
src/KM_fileio.h
src/ST2052_TextParser.cpp

index 188c5b7ebecd54051ff82bd77a3eab019066c607..c768507286d872145790fdd6450aca5e01e9abba 100644 (file)
@@ -349,6 +349,11 @@ namespace AS_02
          Result_t ResolveRID(const byte_t* uuid, ASDCP::TimedText::FrameBuffer& FrameBuf) const;
        };
       
+
+      // Generate UUID asset ID values from file contents
+      Kumu::UUID CreatePNGNameId(const std::string& image_name);
+      Kumu::UUID CreateFontNameId(const std::string& font_name);
+
       //
       class ST2052_TextParser
        {
index 9c57fbe816250099cfb33fa04692bb7f488ac905..b35e8ac456ab0280d93695fce61051c6c3267c96 100644 (file)
@@ -1315,123 +1315,6 @@ Kumu::WriteBufferIntoFile(const Kumu::ByteString& Buffer, const std::string& Fil
 //
 
 
-// Win32 directory scanner
-//
-#ifdef KM_WIN32
-
-//
-Kumu::DirScanner::DirScanner(void) : m_Handle(-1) {}
-
-//
-//
-Result_t
-Kumu::DirScanner::Open(const std::string& filename)
-{
-  // we need to append a '*' to read the entire directory
-  ui32_t fn_len = filename.size(); 
-  char* tmp_file = (char*)malloc(fn_len + 8);
-
-  if ( tmp_file == 0 )
-    return RESULT_ALLOC;
-
-  strcpy(tmp_file, filename.c_str());
-  char* p = &tmp_file[fn_len] - 1;
-
-  if ( *p != '/' && *p != '\\' )
-    {
-      p++;
-      *p++ = '/';
-    }
-
-  *p++ = '*';
-  *p = 0;
-  // whew...
-
-  m_Handle = _findfirsti64(tmp_file, &m_FileInfo);
-  Result_t result = RESULT_OK;
-
-  if ( m_Handle == -1 )
-    result = RESULT_NOT_FOUND;
-
-  return result;
-}
-
-
-//
-//
-Result_t
-Kumu::DirScanner::Close()
-{
-  if ( m_Handle == -1 )
-    return RESULT_FILEOPEN;
-
-  if ( _findclose((long)m_Handle) == -1 )
-    return RESULT_FAIL;
-
-  m_Handle = -1;
-  return RESULT_OK;
-}
-
-
-// This sets filename param to the same per-instance buffer every time, so
-// the value will change on the next call
-Result_t
-Kumu::DirScanner::GetNext(char* filename)
-{
-  KM_TEST_NULL_L(filename);
-
-  if ( m_Handle == -1 )
-    return RESULT_FILEOPEN;
-
-  if ( m_FileInfo.name[0] == '\0' )
-    return RESULT_ENDOFFILE;
-
-  strncpy(filename, m_FileInfo.name, MaxFilePath);
-  Result_t result = RESULT_OK;
-
-  if ( _findnexti64((long)m_Handle, &m_FileInfo) == -1 )
-    {
-      m_FileInfo.name[0] = '\0';
-         
-      if ( errno != ENOENT )
-       result = RESULT_FAIL;
-    }
-
-  return result;
-}
-
-
-//
-Kumu::DirScannerEx::DirScannerEx() : m_Handle(0) {}
-
-//
-Result_t
-Kumu::DirScannerEx::Open(const std::string& dirname)
-{
-  Kumu::DefaultLogSink().Critical("Kumu::DirScannerEx unimplemented for Win32 API.\n");
-  return RESULT_NOTIMPL;
-}
-
-//
-Result_t
-Kumu::DirScannerEx::Close()
-{
-  Kumu::DefaultLogSink().Critical("Kumu::DirScannerEx unimplemented for Win32 API.\n");
-  return RESULT_NOTIMPL;
-}
-
-//
-Result_t
-Kumu::DirScannerEx::GetNext(std::string& next_item_name, DirectoryEntryType_t& next_item_type)
-{
-  Kumu::DefaultLogSink().Critical("Kumu::DirScannerEx unimplemented for Win32 API.\n");
-  return RESULT_NOTIMPL;
-}
-
-#else // KM_WIN32
-
-// POSIX directory scanner
-
 //
 Kumu::DirScanner::DirScanner(void) : m_Handle(NULL) {}
 
@@ -1643,8 +1526,6 @@ Kumu::DirScannerEx::GetNext(std::string& next_item_name, DirectoryEntryType_t& n
   return RESULT_OK;
 }
 
-#endif // KM_WIN32
-
 
 //------------------------------------------------------------------------------------------
 
index 18dcf0ec11e9668b1751e8206bf8fac1d3117795..264509a601e8384493ae86b0f57e913b999955d7 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004-2014, John Hurst
+Copyright (c) 2004-2016, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -37,6 +37,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #ifdef KM_WIN32
 # include <io.h>
+# include "dirent_win.h"
 #else
 # include <dirent.h>
 # include <unistd.h>
@@ -55,12 +56,7 @@ namespace Kumu
   class DirScanner
     {
     public:
-#ifdef KM_WIN32
-      __int64               m_Handle;
-      struct _finddatai64_t m_FileInfo;
-#else
       DIR*       m_Handle;
-#endif
 
       DirScanner(void);
       ~DirScanner() { Close(); }
@@ -83,12 +79,7 @@ namespace Kumu
   class DirScannerEx
   {
     std::string m_Dirname;
-#ifdef KM_WIN32
-    __int64               m_Handle;
-    struct _finddatai64_t m_FileInfo;
-#else
     DIR*       m_Handle;
-#endif
 
     KM_NO_COPY_CONSTRUCT(DirScannerEx);
 
index 5bc2f9d9f707f3d958920d9480d551844e4bfecd..f291a1b213c49f7d285bfbddcf030bb10d1b8719 100644 (file)
@@ -86,15 +86,15 @@ create_4122_type5_id(const std::string& subject_name, const byte_t* ns_id)
 }
 
 //
-static Kumu::UUID
-create_png_name_id(const std::string& image_name)
+Kumu::UUID
+AS_02::TimedText::CreatePNGNameId(const std::string& image_name)
 {
   return create_4122_type5_id(image_name, s_png_id_prefix);
 }
 
 //
-static Kumu::UUID
-create_font_name_id(const std::string& font_name)
+Kumu::UUID
+AS_02::TimedText::CreateFontNameId(const std::string& font_name)
 {
   return create_4122_type5_id(font_name, s_font_id_prefix);
 }
@@ -106,6 +106,7 @@ static std::set<std::string> sg_default_font_family_list;
 static void
 setup_default_font_family_list()
 {
+  AutoMutex l(sg_default_font_family_list_lock);
   sg_default_font_family_list.insert("default");
   sg_default_font_family_list.insert("monospace");
   sg_default_font_family_list.insert("sansSerif");
@@ -166,7 +167,7 @@ AS_02::TimedText::Type5UUIDFilenameResolver::OpenRead(const std::string& dirname
                  // is it PNG?
                  if ( memcmp(read_buffer, PNGMagic, sizeof(PNGMagic)) == 0 )
                    {
-                     UUID asset_id = create_png_name_id(next_item);
+                     UUID asset_id = CreatePNGNameId(PathBasename(next_item));
                      m_ResourceMap.insert(ResourceMap::value_type(asset_id, next_item));
                    }
                  // is it a font?
@@ -174,7 +175,7 @@ AS_02::TimedText::Type5UUIDFilenameResolver::OpenRead(const std::string& dirname
                            || memcmp(read_buffer, TrueTypeMagic, sizeof(TrueTypeMagic)) == 0 )
                    {
                      std::string font_root_name = PathSetExtension(next_item, "");
-                     UUID asset_id = create_font_name_id(font_root_name);
+                     UUID asset_id = CreateFontNameId(PathBasename(font_root_name));
                      m_ResourceMap.insert(ResourceMap::value_type(asset_id, next_item));
                    }
                }
@@ -362,7 +363,7 @@ AS_02::TimedText::ST2052_TextParser::h__TextParser::OpenRead(const std::string&
 
   for ( i = png_visitor.value_list.begin(); i != png_visitor.value_list.end(); ++i )
     {
-      UUID asset_id = create_png_name_id(*i);
+      UUID asset_id = CreatePNGNameId(PathBasename(*i));
       TimedTextResourceDescriptor png_resource;
       memcpy(png_resource.ResourceID, asset_id.Value(), UUIDlen);
       png_resource.Type = ASDCP::TimedText::MT_PNG;
@@ -377,7 +378,7 @@ AS_02::TimedText::ST2052_TextParser::h__TextParser::OpenRead(const std::string&
 
   for ( i = font_visitor.value_list.begin(); i != font_visitor.value_list.end(); ++i )
     {
-      UUID font_id = create_font_name_id(*i);
+      UUID font_id = CreateFontNameId(PathBasename(*i));
 
       if ( PathIsFile(font_id.EncodeHex(buf, 64))
           || PathIsFile(*i+".ttf")