<commit_before>//
// RemotePhotoTool - remote camera control software
// Copyright (C) 2008-2016 <NAME>
//
/// \file MoveScriptGenerator.cpp Generates move cmd script based on image types
//

// includes
#include "stdafx.h"
#include "ImageTypeScanner.hpp"
#include "CommandLineParser.hpp"
#include "Path.hpp"
#include "FileFinder.hpp"
#include "Exif.hpp"
#include <map>

/// main application for generator
class App
{
public:
   /// constructs a new application, using command line arguments
   App(int argc, _TCHAR* argv[])
      :m_imageFileInfos(CollectImageFileInfos(argc, argv))
   {
   }

   /// runs generator
   void Run()
   {
      SortImagesByDateTaken();

      ImageTypeScannerOptions options;
      ImageTypeScanner scanner(options);

      scanner.ScanImages(m_imageFileInfos, m_allImageTypeFileLists);

      PrintScript();
   }

private:
   /// collects image file infos from passed command line arguments
   static std::vector<ImageFileInfo> CollectImageFileInfos(int argc, _TCHAR* argv[])
   {
      std::vector<ImageFileInfo> allImages;

      CommandLineParser parser(argc, argv);

      CString filename;
      parser.GetNext(filename); // ignore first argument, the executable name

      while (parser.GetNext(filename))
      {
         if (Path(filename).FileExists())
            AddImageFile(allImages, filename);
         else
            if (Path(filename).FolderExists())
            {
               FileFinder finder(filename, _T("*.*"));

               if (finder.IsValid())
               {
                  while (finder.Next())
                     if (!finder.IsDot() && finder.IsFile())
                     AddImageFile(allImages, finder.Filename());
               }
            }
      }

      return allImages;
   }

   /// adds a new image file info to the list, for given image file
   static void AddImageFile(std::vector<ImageFileInfo>& allImages, const CString& filename)
   {
      _ftprintf(stderr, _T("Reading image infos for \"%s\"\n"), filename.GetString());

      ImageFileInfo info(filename);

      if (ReadImageInfos(info))
         allImages.push_back(info);
   }

   /// reads image infos for image with filename (already stored in info)
   static bool ReadImageInfos(ImageFileInfo& info)
   {
      Exif::Loader loader;
      loader.LoadFile(info.Filename());

      if (!loader.IsValid())
         return false;

      Exif::Data data = loader.GetData();

      if (!data.IsContentIfdAvail(EXIF_IFD_EXIF))
         return false; // no EXIF IFD

      Exif::Content exif = data.GetContent(EXIF_IFD_EXIF);

      bool autoBracketMode = exif.GetEntry(EXIF_TAG_EXPOSURE_MODE).GetShort() == 2;
      info.AutoBracketMode(autoBracketMode);

      Exif::Entry exposureCompEntry = exif.GetEntry(EXIF_TAG_EXPOSURE_BIAS_VALUE);<commit_msg>added link with some infos about Exif tags<commit_after>//
// RemotePhotoTool - remote camera control software
// Copyright (C) 2008-2016 <NAME>
//
/// \file MoveScriptGenerator.cpp Generates move cmd script based on image types
//

// includes
#include "stdafx.h"
#include "ImageTypeScanner.hpp"
#include "CommandLineParser.hpp"
#include "Path.hpp"
#include "FileFinder.hpp"
#include "Exif.hpp"
#include <map>

/// main application for generator
class App
{
public:
   /// constructs a new application, using command line arguments
   App(int argc, _TCHAR* argv[])
      :m_imageFileInfos(CollectImageFileInfos(argc, argv))
   {
   }

   /// runs generator
   void Run()
   {
      SortImagesByDateTaken();

      ImageTypeScannerOptions options;
      ImageTypeScanner scanner(options);

      scanner.ScanImages(m_imageFileInfos, m_allImageTypeFileLists);

      PrintScript();
   }

private:
   /// collects image file infos from passed command line arguments
   static std::vector<ImageFileInfo> CollectImageFileInfos(int argc, _TCHAR* argv[])
   {
      std::vector<ImageFileInfo> allImages;

      CommandLineParser parser(argc, argv);

      CString filename;
      parser.GetNext(filename); // ignore first argument, the executable name

      while (parser.GetNext(filename))
      {
         if (Path(filename).FileExists())
            AddImageFile(allImages, filename);
         else
            if (Path(filename).FolderExists())
            {
               FileFinder finder(filename, _T("*.*"));

               if (finder.IsValid())
               {
                  while (finder.Next())
                     if (!finder.IsDot() && finder.IsFile())
                     AddImageFile(allImages, finder.Filename());
               }
            }
      }

      return allImages;
   }

   /// adds a new image file info to the list, for given image file
   static void AddImageFile(std::vector<ImageFileInfo>& allImages, const CString& filename)
   {
      _ftprintf(stderr, _T("Reading image infos for \"%s\"\n"), filename.GetString());

      ImageFileInfo info(filename);

      if (ReadImageInfos(info))
         allImages.push_back(info);
   }

   /// reads image infos for image with filename (already stored in info)
   /// \see http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html
   static bool ReadImageInfos(ImageFileInfo& info)
   {
      Exif::Loader loader;
      loader.LoadFile(info.Filename());

      if (!loader.IsValid())
         return false;

      Exif::Data data = loader.GetData();

      if (!data.IsContentIfdAvail(EXIF_IFD_EXIF))
         return false; // no EXIF IFD

      Exif::Content exif = data.GetContent(EXIF_IFD_EXIF);

      bool autoBracketMode = exif.GetEntry(EXIF_TAG_EXPOSURE_MODE).GetShort() == 2;
      info.AutoBracketMode(autoBracketMode);

      Exif::Entry exposureCompEntry = exif.GetEntry(EXIF_TAG_EXPOSURE_BIAS_VALUE);
{'fraction_non_alphanumeric': 0.11327713382507903, 'fraction_numerical': 0.003161222339304531, 'mean_word_length': 2.7100977198697067, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6808090', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1655, 'n_words': 400}