Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
//#define UNICODE  // per le funzioni di conversione da/a UNC
Toshihiro Shimizu 890ddd
#include <windows.h></windows.h>
Toshihiro Shimizu 890ddd
#include <lm.h></lm.h>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const char slash     = '\\';
Shinya Kitaoka 120a6e
const char auxslash  = '/';
Shinya Kitaoka 120a6e
const char wslash    = L'\\';
Toshihiro Shimizu 890ddd
const char wauxslash = L'/';
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
const char slash     = '/';
Shinya Kitaoka 120a6e
const char auxslash  = '\\';
Shinya Kitaoka 120a6e
const char wslash    = '/';
Toshihiro Shimizu 890ddd
const char wauxslash = '\\';
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
shun-iwasawa b5e76b
#include "tfiletype.h"
Shinya Kitaoka 9eb50d
#include <cmath></cmath>
Shinya Kitaoka 9eb50d
#include <cctype></cctype>
tomosu eea0ac
#include <sstream></sstream>
Toshihiro Shimizu 890ddd
jabarrera 96d45c
// QT
jabarrera 96d45c
#include <qobject></qobject>
jabarrera 96d45c
Toshihiro Shimizu 890ddd
bool TFilePath::m_underscoreFormatAllowed = true;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
/*-- fromSeg位置 と
Shinya Kitaoka 120a6e
 * toSeg位置は含まず、それらの間に挟まれている文字列が「数字4ケタ」ならtrueを返す
Shinya Kitaoka 120a6e
 * --*/
Shinya Kitaoka 120a6e
bool isNumbers(std::wstring str, int fromSeg, int toSeg) {
manongjohn 4ee91c
  /*
manongjohn 4ee91c
    if (toSeg - fromSeg != 5) return false;
manongjohn 4ee91c
    for (int pos = fromSeg + 1; pos < toSeg; pos++) {
manongjohn 4ee91c
      if (str[pos] < '0' || str[pos] > '9') return false;
manongjohn 4ee91c
    }
manongjohn 4ee91c
  */
manongjohn 4ee91c
  // Let's check if it follows the format ####A (i.e 00001 or 00001a)
manongjohn 4ee91c
  int numDigits = 0, numLetters = 0;
Shinya Kitaoka 120a6e
  for (int pos = fromSeg + 1; pos < toSeg; pos++) {
manongjohn 4ee91c
    if ((str[pos] >= 'A' && str[pos] <= 'Z') ||
manongjohn 4ee91c
        (str[pos] >= 'a' && str[pos] <= 'z')) {
manongjohn 4ee91c
      // Not the right format if we ran into a letter without first finding a
manongjohn 4ee91c
      // number
manongjohn 4ee91c
      if (!numDigits) return false;
manongjohn 4ee91c
manongjohn 4ee91c
      // We'll keep track of the number of letters we find.
manongjohn 4ee91c
      // NOTE: From here on out we should only see letters
manongjohn 4ee91c
      numLetters++;
manongjohn 4ee91c
    } else if (str[pos] >= '0' && str[pos] <= '9') {
manongjohn 4ee91c
      // Not the right format if we ran into a number that followed a letter.
manongjohn 4ee91c
      // This format is not something we expect currently
manongjohn 4ee91c
      if (numLetters) return false;  // not right format
manongjohn 4ee91c
manongjohn 4ee91c
      // We'll keep track of the number of digits we find.
manongjohn 4ee91c
      numDigits++;
manongjohn 4ee91c
    } else  // Not the right format if we found something we didn't expect
manongjohn 4ee91c
      return false;
Shinya Kitaoka 120a6e
  }
manongjohn 4ee91c
manongjohn 4ee91c
  // Not the right format if we see too many letters.
manongjohn 4ee91c
  // At the time of this logic, we only expect 1 letter.  Can expand to 2 or
manongjohn 4ee91c
  // more later, if we want.
manongjohn 4ee91c
  if (numLetters > 1) return false;
manongjohn 4ee91c
manongjohn 4ee91c
  return true;  // We're good!
manongjohn 4ee91c
}
manongjohn 4ee91c
manongjohn 4ee91c
bool checkForSeqNum(QString type) {
shun-iwasawa b5e76b
  TFileType::Type typeInfo = TFileType::getInfoFromExtension(type);
shun-iwasawa b5e76b
  if ((typeInfo & TFileType::IMAGE) && !(typeInfo & TFileType::LEVEL))
shun-iwasawa b5e76b
    return true;
shun-iwasawa b5e76b
  else
manongjohn 4ee91c
    return false;
Toshihiro Shimizu 890ddd
}
shun-iwasawa b5e76b
};  // namespace
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// TFrameId::operator string() const
Shinya Kitaoka 120a6e
std::string TFrameId::expand(FrameFormat format) const {
Shinya Kitaoka 120a6e
  if (m_frame == EMPTY_FRAME)
Shinya Kitaoka 120a6e
    return "";
Shinya Kitaoka 120a6e
  else if (m_frame == NO_FRAME)
Shinya Kitaoka 120a6e
    return "-";
Shinya Kitaoka 120a6e
  std::ostringstream o_buff;
Shinya Kitaoka 120a6e
  if (format == FOUR_ZEROS || format == UNDERSCORE_FOUR_ZEROS) {
Shinya Kitaoka 120a6e
    o_buff.fill('0');
Shinya Kitaoka 120a6e
    o_buff.width(4);
Shinya Kitaoka 120a6e
    o_buff << m_frame;
Shinya Kitaoka 120a6e
    o_buff.width(0);
manongjohn 4ee91c
  } else if (format == CUSTOM_PAD || format == UNDERSCORE_CUSTOM_PAD) {
manongjohn 4ee91c
    o_buff.fill('0');
manongjohn 4ee91c
    o_buff.width(m_zeroPadding);
manongjohn 4ee91c
    o_buff << m_frame;
manongjohn 4ee91c
    o_buff.width(0);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    o_buff << m_frame;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_letter != '\0') o_buff << m_letter;
Shinya Kitaoka 120a6e
  return o_buff.str();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TFrameId &TFrameId::operator++() {
Shinya Kitaoka 120a6e
  ++m_frame;
Shinya Kitaoka 120a6e
  m_letter = 0;
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TFrameId &TFrameId::operator--() {
Shinya Kitaoka 120a6e
  if (m_letter > 0)
Shinya Kitaoka 120a6e
    m_letter = 0;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    --m_frame;
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool isSlash(char c) { return c == slash || c == auxslash; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool isSlash(wchar_t c) { return c == wslash || c == wauxslash; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// cerca l'ultimo '/' o '\'. Se non c'e' ritorna -1
Shinya Kitaoka 120a6e
// di modo che la sottostringa che parte da getLastSlash() + 1 e'
Shinya Kitaoka 120a6e
// nome.frame.tipo
Shinya Kitaoka 120a6e
inline int getLastSlash(const std::wstring &path) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = path.length() - 1; i >= 0 && !isSlash(path[i]); i--) {
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return i;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void TFilePath::setPath(string path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
bool isUncName = false;
tomosu eea0ac
  // elimino i '//', './' e '/' finali; raddrizzo gli slash 'storti'.
Toshihiro Shimizu 890ddd
  // se il path comincia con  "<alpha>:" aggiungo uno slash</alpha>
tomosu eea0ac
  int length =path.length();
Toshihiro Shimizu 890ddd
  int pos = 0;
Toshihiro Shimizu 890ddd
  if(path.length()>=2 && isalpha(path[0]) && path[1] == ':')
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
     m_path.append(path,0,2);
Toshihiro Shimizu 890ddd
     pos=2;
Toshihiro Shimizu 890ddd
     if(path.length()==2 || !isSlash(path[pos])) m_path.append(1,slash);
Toshihiro Shimizu 890ddd
    }
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
  else  //se si tratta di un path in formato UNC e' del tipo "\\\\MachineName"
Shinya Kitaoka 120a6e
        //RICONTROLLARE! SE SI HA IP ADDRESS FALLIVA!
Shinya Kitaoka 120a6e
    if (path.length() >= 3 && path[0] == '\\' &&  path[1] == '\\' &&
Shinya Kitaoka 120a6e
(isalpha(path[2]) || isdigit(path[2])) )
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
      isUncName = true;
Toshihiro Shimizu 890ddd
      m_path.append(path,0,3);
Toshihiro Shimizu 890ddd
      pos = 3;
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
  for(;pos
Toshihiro Shimizu 890ddd
    if(path[pos] == '.')
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      pos++;
tomosu eea0ac
      if(pos>=length)
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
        if(pos>1) m_path.append(1,'.');
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
      else if(!isSlash(path[pos])) m_path.append(path,pos-1,2);
Toshihiro Shimizu 890ddd
      else {
tomosu eea0ac
         while(pos+1
Toshihiro Shimizu 890ddd
           pos++;
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
    else if(isSlash(path[pos]))
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      do pos++;
Toshihiro Shimizu 890ddd
      while(pos
Toshihiro Shimizu 890ddd
      pos--;
Toshihiro Shimizu 890ddd
      m_path.append(1,slash);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
    else
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      m_path.append(1,path[pos]);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // rimuovo l'eventuale '/' finale (a meno che m_path == "/" o m_path ==
Shinya Kitaoka 120a6e
"<letter>:\"</letter>
Toshihiro Shimizu 890ddd
    // oppure sia UNC (Windows only) )
Toshihiro Shimizu 890ddd
    if(!(m_path.length()==1 && m_path[0] == slash ||
Shinya Kitaoka 120a6e
         m_path.length()==3 && isalpha(m_path[0]) && m_path[1] == ':' &&
Shinya Kitaoka 120a6e
m_path[2] == slash)
Toshihiro Shimizu 890ddd
      && m_path.length()>1 && m_path[m_path.length()-1] == slash)
Toshihiro Shimizu 890ddd
      m_path.erase(m_path.length()-1, 1);
tomosu eea0ac
Shinya Kitaoka 120a6e
  if (isUncName && m_path.find_last_of('\\') == 1) // e' indicato solo il nome
Shinya Kitaoka 120a6e
della macchina...
Toshihiro Shimizu 890ddd
    m_path.append(1, slash);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void append(string &out, wchar_t c)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
  if(32 <= c && c<=127 && c!='&') out.append(1, (char)c);
Toshihiro Shimizu 890ddd
  else if(c=='&') out.append("&");
tomosu eea0ac
  else
Toshihiro Shimizu 890ddd
    {
tomosu eea0ac
     ostringstream ss;
Toshihiro Shimizu 890ddd
     ss << "&#" <<  c << ";" << '\0';
Toshihiro Shimizu 890ddd
     out += ss.str();
Toshihiro Shimizu 890ddd
     ss.freeze(0);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFilePath::setPath(std::wstring path) {
Shinya Kitaoka 120a6e
  bool isUncName = false;
Shinya Kitaoka 120a6e
  // elimino i '//', './' e '/' finali; raddrizzo gli slash 'storti'.
Shinya Kitaoka 120a6e
  // se il path comincia con  "<alpha>:" aggiungo uno slash</alpha>
Shinya Kitaoka 120a6e
  int length = path.length();
Shinya Kitaoka 120a6e
  int pos    = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (path.length() >= 2 && iswalpha(path[0]) && path[1] == L':') {
Shinya Kitaoka 120a6e
    m_path.append(1, (wchar_t)path[0]);
Shinya Kitaoka 120a6e
    m_path.append(1, L':');
Shinya Kitaoka 120a6e
    // m_path.append(path,0,2);
Shinya Kitaoka 120a6e
    pos = 2;
Shinya Kitaoka 120a6e
    if (path.length() == 2 || !isSlash(path[pos])) m_path.append(1, wslash);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // se si tratta di un path in formato UNC e' del tipo "\\\\MachineName"
Rozhuk Ivan 823a31
  else if ((path.length() >= 3 && path[0] == L'\\' && path[1] == L'\\' &&
Rozhuk Ivan 823a31
               iswalnum(path[2])) ||
Rozhuk Ivan 823a31
           (path.length() >= 3 && path[0] == L'/' && path[1] == L'/' &&
Rozhuk Ivan 823a31
               iswalnum(path[2]))) {
Shinya Kitaoka 120a6e
    isUncName = true;
Shinya Kitaoka 120a6e
    m_path.append(2, L'\\');
Shinya Kitaoka 120a6e
    m_path.append(1, path[2]);
Shinya Kitaoka 120a6e
    pos = 3;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (; pos < length; pos++)
Shinya Kitaoka 120a6e
    if (path[pos] == L'.') {
Shinya Kitaoka 120a6e
      pos++;
Shinya Kitaoka 120a6e
      if (pos >= length) {
Shinya Kitaoka 120a6e
        if (pos > 1) m_path.append(1, L'.');
Shinya Kitaoka 120a6e
      } else if (!isSlash(path[pos])) {
Shinya Kitaoka 120a6e
        m_path.append(1, L'.');
Shinya Kitaoka 120a6e
        m_path.append(1, path[pos]);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        while (pos + 1 < length && isSlash(path[pos + 1])) pos++;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (isSlash(path[pos])) {
Shinya Kitaoka 120a6e
      int firstSlashPos = pos;
Shinya Kitaoka 120a6e
      do
Shinya Kitaoka 120a6e
        pos++;
Shinya Kitaoka 120a6e
      while (pos < length && isSlash(path[pos]));
Shinya Kitaoka 120a6e
      if (firstSlashPos == 0 && pos == 4)  // Caso "\\\\MachineName"
Shinya Kitaoka 120a6e
        m_path.append(2, wslash);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_path.append(1, wslash);
Shinya Kitaoka 120a6e
      pos--;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_path.append(1, path[pos]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // rimuovo l'eventuale '/' finale (a meno che m_path == "/" o m_path ==
Shinya Kitaoka 120a6e
  // "<letter>:\"</letter>
Shinya Kitaoka 120a6e
  // oppure sia UNC (Windows only) )
Rozhuk Ivan 823a31
  if (!((m_path.length() == 1 && m_path[0] == wslash) ||
Rozhuk Ivan 823a31
        (m_path.length() == 3 && iswalpha(m_path[0]) && m_path[1] == L':' &&
Rozhuk Ivan 823a31
            m_path[2] == wslash)) &&
Rozhuk Ivan 823a31
      (m_path.length() > 1 && m_path[m_path.length() - 1] == wslash))
Shinya Kitaoka 120a6e
    m_path.erase(m_path.length() - 1, 1);
Shinya Kitaoka 120a6e
shun-iwasawa 85c995
  if (isUncName &&
shun-iwasawa 85c995
      !(m_path.find_last_of(L'\\') > 1 ||
shun-iwasawa 85c995
        m_path.find_last_of(L'/') >
shun-iwasawa 85c995
            1))  // e' indicato solo il nome della macchina...
Shinya Kitaoka 120a6e
    m_path.append(1, wslash);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const char *path) { setPath(::to_wstring(path)); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const std::string &path) { setPath(::to_wstring(path)); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const std::wstring &path) { setPath(path); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const QString &path) { setPath(path.toStdWString()); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool TFilePath::operator==(const TFilePath &fp) const {
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  return _wcsicmp(m_path.c_str(), fp.m_path.c_str()) == 0;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  return m_path == fp.m_path;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::operator<(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  std::wstring iName = m_path;
Shinya Kitaoka 120a6e
  std::wstring jName = fp.m_path;
Shinya Kitaoka 120a6e
  int i1 = 0, j1 = 0;
Shinya Kitaoka 120a6e
  int i2 = m_path.find(L"\\");
Shinya Kitaoka 120a6e
  int j2 = fp.m_path.find(L"\\");
Shinya Kitaoka 120a6e
  if (i2 == j2 && j2 == -1)
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
    return _wcsicmp(m_path.c_str(), fp.m_path.c_str()) < 0;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    return m_path < fp.m_path;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  if (!i2) {
Shinya Kitaoka 120a6e
    ++i1;
Shinya Kitaoka 120a6e
    i2 = m_path.find(L"\\", i1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (!j2) {
Shinya Kitaoka 120a6e
    ++j1;
Shinya Kitaoka 120a6e
    j2 = fp.m_path.find(L"\\", j1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  while (i2 != -1 || j2 != -1) {
Shinya Kitaoka 120a6e
    iName = (i2 != -1) ? m_path.substr(i1, i2 - i1) : m_path;
Shinya Kitaoka 120a6e
    jName = (j2 != -1) ? fp.m_path.substr(j1, j2 - j1) : fp.m_path;
Shinya Kitaoka 120a6e
// se le due parti di path, conpresi tra slash sono uguali
Shinya Kitaoka 120a6e
// itero il processo di confronto altrimenti ritorno
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
    char differ;
Shinya Kitaoka 120a6e
    differ = _wcsicmp(iName.c_str(), jName.c_str());
Shinya Kitaoka 120a6e
    if (differ != 0) return differ < 0 ? true : false;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    if (TFilePath(iName) != TFilePath(jName))
Shinya Kitaoka 120a6e
      return TFilePath(iName) < TFilePath(jName);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    i1 = (i2 != -1) ? i2 + 1 : m_path.size();
Shinya Kitaoka 120a6e
    j1 = (j2 != -1) ? j2 + 1 : fp.m_path.size();
Shinya Kitaoka 120a6e
    i2 = m_path.find(L"\\", i1);
Shinya Kitaoka 120a6e
    j2 = fp.m_path.find(L"\\", j1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  iName = m_path.substr(i1, m_path.size() - i1);
Shinya Kitaoka 120a6e
  jName = fp.m_path.substr(j1, fp.m_path.size() - j1);
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  return _wcsicmp(iName.c_str(), jName.c_str()) < 0;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  return TFilePath(iName) < TFilePath(jName);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef LEVO
Shinya Kitaoka 120a6e
bool TFilePath::operator<(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
wstring a = m_path, b = fp.m_path;
Shinya Kitaoka 120a6e
for(;;)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
wstring ka,kb;
Shinya Kitaoka 120a6e
int i;
Shinya Kitaoka 120a6e
i = a.find_first_of("/\\");
Shinya Kitaoka 120a6e
if(i==wstring::npos) {ka = a; a = L"";}
Shinya Kitaoka 120a6e
i = b.find_first_of("/\\");
Shinya Kitaoka 120a6e
if(i==wstring::npos) {ka = a; a = L"";}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  wstring a = toLower(m_path), b = toLower(fp.m_path);
Shinya Kitaoka 120a6e
  return a < b;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath &TFilePath::operator+=(const TFilePath &fp) {
Shinya Kitaoka 120a6e
  assert(!fp.isAbsolute());
Shinya Kitaoka 120a6e
  if (fp.isEmpty())
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  else if (isEmpty()) {
Shinya Kitaoka 120a6e
    *this = fp;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  } else if (m_path.length() != 1 || m_path[0] != slash) {
Shinya Kitaoka 120a6e
    assert(!m_path.empty());
Shinya Kitaoka 120a6e
    if (!isSlash(m_path[m_path.length() - 1])) m_path.append(1, wslash);
Shinya Kitaoka 120a6e
    m_path += fp.m_path;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    *this = TFilePath(m_path + fp.m_path);
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
TFilePath TFilePath::operator+(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  TFilePath ret(*this);
Shinya Kitaoka 120a6e
  ret += fp;
Shinya Kitaoka 120a6e
  return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath &TFilePath::operator+=(const std::wstring &s) {
Shinya Kitaoka 120a6e
  if (s.empty()) return *this;
Shinya Kitaoka 120a6e
  // if(m_path.length()!=1 || m_path[0] != slash)
Shinya Kitaoka 120a6e
  //  m_path += slash;
Shinya Kitaoka 120a6e
  if (m_path.length() > 0 && !isSlash(m_path[m_path.length() - 1]))
Shinya Kitaoka 120a6e
    m_path.append(1, wslash);
Shinya Kitaoka 120a6e
  m_path += s;
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const std::wstring TFilePath::getWideString() const {
Shinya Kitaoka 120a6e
  return m_path;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
std::wstring s;
Shinya Kitaoka 120a6e
int n = m_path.size();
Shinya Kitaoka 120a6e
for(int i=0;i
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
char c = m_path[i];
Shinya Kitaoka 120a6e
if(c!='&') s.append(1, (unsigned short)c);
Shinya Kitaoka 120a6e
else
Shinya Kitaoka 120a6e
 {
Shinya Kitaoka 120a6e
  i++;
Shinya Kitaoka 120a6e
  if(m_path[i] == '#')
Toshihiro Shimizu 890ddd
    {
Shinya Kitaoka 120a6e
     unsigned short w = 0;
Shinya Kitaoka 120a6e
     i++;
Shinya Kitaoka 120a6e
     while(i
Toshihiro Shimizu 890ddd
       {
Shinya Kitaoka 120a6e
        c = m_path[i];
Shinya Kitaoka 120a6e
        if('0'<=c && c<='9')
Shinya Kitaoka 120a6e
          w = w*10 + c - '0';
Shinya Kitaoka 120a6e
        else if('a' <=c && c<='f')
Shinya Kitaoka 120a6e
          w = w*10 + c - 'a' + 10;
Shinya Kitaoka 120a6e
        else if('A' <=c && c<='F')
Shinya Kitaoka 120a6e
          w = w*10 + c - 'A' + 10;
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          break;
Toshihiro Shimizu 890ddd
        i++;
Toshihiro Shimizu 890ddd
       }
Shinya Kitaoka 120a6e
     s.append(1, w);
Toshihiro Shimizu 890ddd
    }
Shinya Kitaoka 120a6e
 }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
return s;
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
const wstring TFilePath::getWideString() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
   wstring a(L"dummy string");
Toshihiro Shimizu 890ddd
   return a;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TFilePath::getQString() const {
Shinya Kitaoka 120a6e
  return QString::fromStdWString(getWideString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::ostream &operator<<(std::ostream &out, const TFilePath &path) {
Shinya Kitaoka 120a6e
  std::wstring w = path.getWideString();
Shinya Kitaoka 120a6e
  return out << ::to_string(w) << " ";
Shinya Kitaoka 120a6e
  //  string w = path.getString();
Shinya Kitaoka 120a6e
  //  return out << w << " ";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
TFilePath TFilePath::operator+ (const TFilePath &fp) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
assert(!fp.isAbsolute());
Toshihiro Shimizu 890ddd
if(fp.isEmpty()) return *this;
Toshihiro Shimizu 890ddd
else if(isEmpty()) return fp;
tomosu eea0ac
else if(m_path.length()!=1 || m_path[0] != slash)
Toshihiro Shimizu 890ddd
  return TFilePath(m_path + slash + fp.m_path);
tomosu eea0ac
else
Toshihiro Shimizu 890ddd
  return TFilePath(m_path + fp.m_path);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::isAbsolute() const {
Rozhuk Ivan 823a31
  return ((m_path.length() >= 1 && m_path[0] == slash) ||
Rozhuk Ivan 823a31
          (m_path.length() >= 2 && iswalpha(m_path[0]) && m_path[1] == ':'));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::isRoot() const {
Rozhuk Ivan 823a31
  return ((m_path.length() == 1 && m_path[0] == slash) ||
Rozhuk Ivan 823a31
          (m_path.length() == 3 && iswalpha(m_path[0]) && m_path[1] == ':' &&
Rozhuk Ivan 823a31
             m_path[2] == slash) ||
Rozhuk Ivan 823a31
          ((m_path.length() > 2 && m_path[0] == slash && m_path[1] == slash) &&
Shinya Kitaoka 120a6e
             (std::string::npos == m_path.find(slash, 2) ||
Rozhuk Ivan 823a31
              m_path.find(slash, 2) == (m_path.size() - 1))));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// ritorna ""(niente tipo, niente punto), "." (file con tipo) o ".." (file con
Shinya Kitaoka 120a6e
// tipo e frame)
Shinya Kitaoka 120a6e
std::string TFilePath::getDots() const {
manongjohn 4ee91c
  QString type = QString::fromStdString(getType()).toLower();
Jeremy Bullock d8339e
  if (isFfmpegType()) return ".";
Shinya Kitaoka 120a6e
  int i            = getLastSlash(m_path);
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  // potrei anche avere a.b.c.d dove d e' l'estensione
Shinya Kitaoka 120a6e
  i = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos || str == L"..") return "";
Toshihiro Shimizu 890ddd
manongjohn 4ee91c
  int j = str.substr(0, i).rfind(L".");
manongjohn 4ee91c
  if (j == (int)std::wstring::npos && m_underscoreFormatAllowed)
manongjohn 4ee91c
    j = str.substr(0, i).rfind(L"_");
manongjohn 4ee91c
manongjohn 4ee91c
  if (j != (int)std::wstring::npos)
manongjohn 4ee91c
    return (j == i - 1 || (checkForSeqNum(type) && isNumbers(str, j, i))) ? ".."
manongjohn 4ee91c
                                                                          : ".";
manongjohn 4ee91c
  else
Shinya Kitaoka 120a6e
    return ".";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TFilePath::getDottedType()
Shinya Kitaoka 120a6e
    const  // ritorna l'estensione con PUNTO (se c'e')
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  int i            = getLastSlash(m_path);
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  i                = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos) return "";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return toLower(::to_string(str.substr(i)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TFilePath::getUndottedType()
Shinya Kitaoka 120a6e
    const  // ritorna l'estensione senza PUNTO
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  size_t i         = getLastSlash(m_path);
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  i                = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == std::wstring::npos || i == str.length() - 1) return "";
Shinya Kitaoka 120a6e
  return toLower(::to_string(str.substr(i + 1)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::wstring TFilePath::getWideName() const  // noDot! noSlash!
Toshihiro Shimizu 890ddd
{
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  i                = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos) return str;
Shinya Kitaoka 120a6e
  int j = str.substr(0, i).rfind(L".");
manongjohn 4ee91c
  if (j != (int)std::wstring::npos) {
manongjohn 4ee91c
    if (checkForSeqNum(type) && isNumbers(str, j, i)) i = j;
manongjohn 4ee91c
  } else if (m_underscoreFormatAllowed) {
Shinya Kitaoka 120a6e
    j = str.substr(0, i).rfind(L"_");
manongjohn 4ee91c
    if (j != (int)std::wstring::npos && checkForSeqNum(type) &&
manongjohn 4ee91c
        isNumbers(str, j, i))
manongjohn 4ee91c
      i = j;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return str.substr(0, i);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TFilePath::getName() const  // noDot! noSlash!
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  return ::to_string(getWideName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// es. TFilePath("/pippo/pluto.0001.gif").getLevelName() == "pluto..gif"
Shinya Kitaoka 120a6e
std::string TFilePath::getLevelName() const {
Shinya Kitaoka 120a6e
  return ::to_string(getLevelNameW());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Martin van Zijl 4e3671
// es. TFilePath("/pippo/pluto.0001.gif").getLevelName() == "pluto..gif"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::wstring TFilePath::getLevelNameW() const {
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' m_path senza directory
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Jeremy Bullock d8339e
  if (isFfmpegType()) return str;
Shinya Kitaoka 120a6e
  int j = str.rfind(L".");                       // str[j..] = ".type"
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) return str;  // no frame; no type
Shinya Kitaoka 120a6e
  i = str.substr(0, j).rfind(L'.');
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos && m_underscoreFormatAllowed)
Shinya Kitaoka 120a6e
    i = str.substr(0, j).rfind(L'_');
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (j == i || j - i == 1)  // prova.tif o prova..tif
Shinya Kitaoka 120a6e
    return str;
Toshihiro Shimizu 890ddd
Martin van Zijl 4e3671
  if (!checkForSeqNum(type) || !isNumbers(str, i, j) ||
Martin van Zijl 4e3671
      i == (int)std::wstring::npos) return str;
Shinya Kitaoka 120a6e
  // prova.0001.tif
Shinya Kitaoka 120a6e
  return str.erase(i + 1, j - i - 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::getParentDir() const  // noSlash!
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  int i = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  if (i < 0) {
Rozhuk Ivan 823a31
    if (m_path.length() >= 2 && (('a' <= m_path[0] && m_path[0] <= 'z') ||
Rozhuk Ivan 823a31
                                 ('A' <= m_path[0] && m_path[0] <= 'Z')) &&
Shinya Kitaoka 120a6e
        m_path[1] == ':')
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, 2));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath("");
Shinya Kitaoka 120a6e
  } else if (i == 0)
Shinya Kitaoka 120a6e
    return TFilePath("/");
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return TFilePath(m_path.substr(0, i));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::isLevelName() const {
manongjohn 4ee91c
  QString type = QString::fromStdString(getType()).toLower();
manongjohn 4ee91c
  if (isFfmpegType() || !checkForSeqNum(type)) return false;
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    return getFrame() == TFrameId(TFrameId::EMPTY_FRAME);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  catch (...) {
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFrameId TFilePath::getFrame() const {
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 120a6e
  i                = str.rfind(L'.');
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos || str == L"." || str == L"..")
Shinya Kitaoka 120a6e
    return TFrameId(TFrameId::NO_FRAME);
Shinya Kitaoka 120a6e
  int j;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  j = str.substr(0, i).rfind(L'.');
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos && m_underscoreFormatAllowed)
Shinya Kitaoka 120a6e
    j = str.substr(0, i).rfind(L'_');
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) return TFrameId(TFrameId::NO_FRAME);
Shinya Kitaoka 120a6e
  if (i == j + 1) return TFrameId(TFrameId::EMPTY_FRAME);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*-- 間が数字でない場合(ファイル名にまぎれた"_" や "."がある場合)を除外する
Shinya Kitaoka 120a6e
   * --*/
manongjohn 4ee91c
  if (!checkForSeqNum(type) || !isNumbers(str, j, i))
manongjohn 4ee91c
    return TFrameId(TFrameId::NO_FRAME);
Toshihiro Shimizu 890ddd
manongjohn 4ee91c
  int k, number = 0, digits = 0;
manongjohn 4ee91c
  for (k = j + 1; k < i && iswdigit(str[k]); k++) {
manongjohn 4ee91c
    digits++;
manongjohn 4ee91c
    number = number * 10 + str[k] - L'0';
manongjohn 4ee91c
  }
shun-iwasawa 85c995
  char letter                  = '\0';
Shinya Kitaoka 120a6e
  if (iswalpha(str[k])) letter = str[k++] + ('a' - L'a');
John Dancel c7c567
  /*
John Dancel c7c567
    if (number == 0 || k < i)  // || letter!='\0')
John Dancel c7c567
      throw TMalformedFrameException(
John Dancel c7c567
          *this,
John Dancel c7c567
          str + L": " + QObject::tr("Malformed frame name").toStdWString());
John Dancel c7c567
  */
manongjohn 4ee91c
  int padding = 0;
manongjohn 4ee91c
manongjohn 4ee91c
  if (str[j + 1] == '0') padding = digits;
manongjohn 4ee91c
manongjohn 4ee91c
  return TFrameId(number, letter, padding, str[j]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock d8339e
bool TFilePath::isFfmpegType() const {
Jeremy Bullock d8339e
  QString type = QString::fromStdString(getType()).toLower();
Jeremy Bullock d8339e
  if (type == "gif" || type == "mp4" || type == "webm")
Jeremy Bullock d8339e
    return true;
Jeremy Bullock d8339e
  else
Jeremy Bullock d8339e
    return false;
Jeremy Bullock d8339e
}
Jeremy Bullock d8339e
Jeremy Bullock d8339e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
TFilePath TFilePath::withType(const std::string &type) const {
Shinya Kitaoka 120a6e
  assert(type.length() < 2 || type.substr(0, 2) != "..");
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
Shinya Kitaoka 120a6e
  int j            = str.rfind(L'.');
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos || str == L"..")
Shinya Kitaoka 120a6e
  // il path originale non ha tipo
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    if (type == "")
Shinya Kitaoka 120a6e
      return *this;
Shinya Kitaoka 120a6e
    else if (type[0] == '.')
Shinya Kitaoka 120a6e
      return TFilePath(m_path + ::to_wstring(type));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath(m_path + ::to_wstring("." + type));
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
  // il path originale ha gia' il tipo
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    if (type == "")
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, i + j + 1));
Shinya Kitaoka 120a6e
    else if (type[0] == '.')
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, i + j + 1) + ::to_wstring(type));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, i + j + 2) + ::to_wstring(type));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::withName(const std::string &name) const {
Shinya Kitaoka 120a6e
  return withName(::to_wstring(name));
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TFilePath TFilePath::withName(const std::wstring &name) const {
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 120a6e
  int j;
Shinya Kitaoka 120a6e
  j = str.rfind(L'.');
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) {
Shinya Kitaoka 120a6e
    if (m_underscoreFormatAllowed) {
Shinya Kitaoka 120a6e
      j = str.rfind(L'_');
Shinya Kitaoka 120a6e
      if (j != (int)std::wstring::npos)
Shinya Kitaoka 120a6e
        return TFilePath(m_path.substr(0, i + 1) + name + str.substr(j));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return TFilePath(m_path.substr(0, i + 1) + name);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int k;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  k = str.substr(0, j).rfind(L".");
Shinya Kitaoka 120a6e
  if (k == (int)std::wstring::npos && m_underscoreFormatAllowed)
Shinya Kitaoka 120a6e
    k = str.substr(0, j).rfind(L"_");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (k == (int)(std::wstring::npos))
Shinya Kitaoka 120a6e
    k = j;
manongjohn 4ee91c
  else if (k != j - 1 && (!checkForSeqNum(type) || !isNumbers(str, k, j)))
Shinya Kitaoka 120a6e
    k = j;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return TFilePath(m_path.substr(0, i + 1) + name + str.substr(k));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::withParentDir(const TFilePath &dir) const {
Shinya Kitaoka 120a6e
  int i = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  return dir + TFilePath(m_path.substr(i + 1));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::withFrame(const TFrameId &frame,
Shinya Kitaoka 120a6e
                               TFrameId::FrameFormat format) const {
Shinya Kitaoka 120a6e
  const std::wstring dot = L".", dotDot = L"..";
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 120a6e
  assert(str != dot && str != dotDot);
Shinya Kitaoka 120a6e
  int j          = str.rfind(L'.');
Shinya Kitaoka 120a6e
  const char *ch = ".";
manongjohn 4ee91c
  // Override format input because it may be wrong.
manongjohn 4ee91c
  if (!isFfmpegType() && checkForSeqNum(type))
manongjohn 4ee91c
    format = frame.getCurrentFormat();
Shinya Kitaoka 120a6e
  if (m_underscoreFormatAllowed && (format == TFrameId::UNDERSCORE_FOUR_ZEROS ||
manongjohn 4ee91c
                                    format == TFrameId::UNDERSCORE_NO_PAD ||
manongjohn 4ee91c
                                    format == TFrameId::UNDERSCORE_CUSTOM_PAD))
Shinya Kitaoka 120a6e
    ch = "_";
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) {
Shinya Kitaoka 120a6e
    if (frame.isEmptyFrame() || frame.isNoFrame())
Shinya Kitaoka 120a6e
      return *this;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath(m_path + ::to_wstring(ch + frame.expand(format)));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
manongjohn 4ee91c
  int k = str.substr(0, j).rfind(L'.');
manongjohn 4ee91c
manongjohn 4ee91c
  bool hasValidFrameNum = false;
manongjohn 4ee91c
  if (!isFfmpegType() && checkForSeqNum(type) && isNumbers(str, k, j))
manongjohn 4ee91c
    hasValidFrameNum = true;
Shinya Kitaoka 120a6e
  std::string frameString;
shun-iwasawa 85c995
  if (frame.isNoFrame())
shun-iwasawa 85c995
    frameString = "";
shun-iwasawa 85c995
  else if (!frame.isEmptyFrame() && getDots() != "." && !hasValidFrameNum) {
manongjohn 4ee91c
    if (k != (int)std::wstring::npos) {
manongjohn 4ee91c
      std::wstring wstr = str.substr(k, j - k);
manongjohn 4ee91c
      std::string str2(wstr.begin(), wstr.end());
manongjohn 4ee91c
      frameString = str2;
manongjohn 4ee91c
    } else
manongjohn 4ee91c
      frameString = "";
manongjohn 4ee91c
  } else
Shinya Kitaoka 120a6e
    frameString = ch + frame.expand(format);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (k != (int)std::wstring::npos)
Shinya Kitaoka 120a6e
    return TFilePath(m_path.substr(0, k + i + 1) + ::to_wstring(frameString) +
Shinya Kitaoka 120a6e
                     str.substr(j));
Shinya Kitaoka 120a6e
  else if (m_underscoreFormatAllowed) {
Shinya Kitaoka 120a6e
    k = str.substr(0, j).rfind(L'_');
Shinya Kitaoka 120a6e
    if (k != (int)std::wstring::npos &&
Shinya Kitaoka 120a6e
        (k == j - 1 ||
manongjohn 4ee91c
         (checkForSeqNum(type) &&
manongjohn 4ee91c
          isNumbers(str, k,
manongjohn 4ee91c
                    j)))) /*-- "_." の並びか、"_[数字]."の並びのとき --*/
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, k + i + 1) +
Shinya Kitaoka 120a6e
                       ((frame.isNoFrame())
Shinya Kitaoka 120a6e
                            ? L""
Shinya Kitaoka 120a6e
                            : ::to_wstring("_" + frame.expand(format))) +
Shinya Kitaoka 120a6e
                       str.substr(j));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return TFilePath(m_path.substr(0, j + i + 1) + ::to_wstring(frameString) +
Shinya Kitaoka 120a6e
                   str.substr(j));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::isAncestorOf(const TFilePath &possibleDescendent) const {
Shinya Kitaoka 120a6e
  size_t len = m_path.length();
Shinya Kitaoka 120a6e
  if (len == 0) {
Shinya Kitaoka 120a6e
    // il punto e' antenato di tutti i path non assoluti
Shinya Kitaoka 120a6e
    return !possibleDescendent.isAbsolute();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // un path e' antenato di se stesso
Shinya Kitaoka 120a6e
  if (m_path == possibleDescendent.m_path) return true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int possibleDescendentLen = possibleDescendent.m_path.length();
Shinya Kitaoka 120a6e
  // altrimenti l'antenato deve essere piu' corto
Shinya Kitaoka 120a6e
  if ((int)len >= possibleDescendentLen) return false;
Shinya Kitaoka 120a6e
  // e deve coincidere con la prima parte del discendente
Shinya Kitaoka 120a6e
  if (toLower(m_path) != toLower(possibleDescendent.m_path.substr(0, len)))
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  // se l'antenato non finisce con slash ci deve essere uno slash nel
Shinya Kitaoka 120a6e
  // discendente, subito dopo
Shinya Kitaoka 120a6e
  if (m_path[len - 1] != wslash && possibleDescendent.m_path[len] != wslash)
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::operator-(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  if (toLower(m_path) == toLower(fp.m_path)) return TFilePath("");
Shinya Kitaoka 120a6e
  if (!fp.isAncestorOf(*this)) return *this;
Shinya Kitaoka 120a6e
  int len = fp.m_path.length();
Shinya Kitaoka 120a6e
  if (len == 0 || fp.m_path[len - 1] != wslash) len++;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return TFilePath(m_path.substr(len));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::match(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  return getParentDir() == fp.getParentDir() && getName() == fp.getName() &&
Shinya Kitaoka 120a6e
         getFrame() == fp.getFrame() && getType() == fp.getType();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TFilePath::split(std::wstring &head, TFilePath &tail) const {
Shinya Kitaoka 120a6e
  TFilePath ancestor = getParentDir();
Shinya Kitaoka 120a6e
  if (ancestor == TFilePath()) {
Shinya Kitaoka 120a6e
    head = getWideString();
Shinya Kitaoka 120a6e
    tail = TFilePath();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (;;) {
Shinya Kitaoka 120a6e
    if (ancestor.isRoot()) break;
Shinya Kitaoka 120a6e
    TFilePath p = ancestor.getParentDir();
Shinya Kitaoka 120a6e
    if (p == TFilePath()) break;
Shinya Kitaoka 120a6e
    ancestor = p;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  head = ancestor.getWideString();
Shinya Kitaoka 120a6e
  tail = *this - ancestor;
Toshihiro Shimizu 890ddd
}