Exemple #1
0
bool IsDevicePath(CFSTR s) throw()
{
  #ifdef UNDER_CE

  s = s;
  return false;
  /*
  // actually we don't know the way to open device file in WinCE.
  unsigned len = MyStringLen(s);
  if (len < 5 || len > 5 || memcmp(s, FTEXT("DSK"), 3 * sizeof(FChar)) != 0)
    return false;
  if (s[4] != ':')
    return false;
  // for reading use SG_REQ sg; if (DeviceIoControl(dsk, IOCTL_DISK_READ));
  */
  
  #else
  
  if (!IS_DEVICE_PATH(s))
    return false;
  unsigned len = MyStringLen(s);
  if (len == 6 && s[5] == ':')
    return true;
  if (len < 18 || len > 22 || memcmp(s + kDevicePathPrefixSize, FTEXT("PhysicalDrive"), 13 * sizeof(FChar)) != 0)
    return false;
  for (unsigned i = 17; i < len; i++)
    if (s[i] < '0' || s[i] > '9')
      return false;
  return true;
  
  #endif
}
Exemple #2
0
BOOL CLangPage::OnInitDialog()
{
  CPropertyPage::OnInitDialog();

  LangSetDlgItems(*this, kLangIDs, ARRAY_SIZE(kLangIDs));

  UString temp = NWindows::MyLoadString(IDS_LANG_ENGLISH);
  NativeLangString(temp, NWindows::MyLoadString(IDS_LANG_NATIVE));
  int index = (int)m_cmbLang.AddString(GetSystemString(temp));
  m_cmbLang.SetItemData(index, _paths.Size());
  _paths.Add(L"-");
  m_cmbLang.SetCurSel(0);

  const FString dirPrefix = GetLangDirPrefix();
  NWindows::NFile::NFind::CEnumerator enumerator(dirPrefix + FTEXT("*.txt"));
  NWindows::NFile::NFind::CFileInfo fi;
  CLang lang;
  UString error;

  while (enumerator.Next(fi))
  {
    if (fi.IsDir())
      continue;
    const int kExtSize = 4;
    if (fi.Name.Len() < kExtSize)
      continue;
    unsigned pos = fi.Name.Len() - kExtSize;
    if (!StringsAreEqualNoCase_Ascii(fi.Name.Ptr(pos), ".txt"))
      continue;

    if (!LangOpen(lang, dirPrefix + fi.Name))
    {
      error.Add_Space_if_NotEmpty();
      error += fs2us(fi.Name);
      continue;
    }

    const UString shortName = fs2us(fi.Name.Left(pos));
    UString s = shortName;
    const wchar_t *eng = lang.Get(IDS_LANG_ENGLISH);
    if (eng)
      s = eng;
    const wchar_t *native = lang.Get(IDS_LANG_NATIVE);
    if (native)
      NativeLangString(s, native);
    index = (int)m_cmbLang.AddString(GetSystemString(s));
    m_cmbLang.SetItemData(index, _paths.Size());
    _paths.Add(shortName);
    if (g_LangID.IsEqualTo_NoCase(shortName))
      m_cmbLang.SetCurSel(index);
  }

  if (!error.IsEmpty())
    ::MessageBoxW(m_hWnd, error, L"Error in Lang file", MB_ICONERROR);

  return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}
Exemple #3
0
FString GetModuleDirPrefix()
{
  FString s;

  const char *p7zip_home_dir = getenv("P7ZIP_HOME_DIR");
  if (p7zip_home_dir) {
    return MultiByteToUnicodeString(p7zip_home_dir,CP_ACP);
  }

  return FTEXT(".") FSTRING_PATH_SEPARATOR;
}
Exemple #4
0
static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COutFile *outFile)
{
  UInt32 d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId();
  for (unsigned i = 0; i < 100; i++)
  {
    path = prefix;
    if (addRandom)
    {
      FChar s[16];
      UInt32 value = d;
      unsigned k;
      for (k = 0; k < 8; k++)
      {
        unsigned t = value & 0xF;
        value >>= 4;
        s[k] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
      }
      s[k] = '\0';
      if (outFile)
        path += FChar('.');
      path += s;
      UInt32 step = GetTickCount() + 2;
      if (step == 0)
        step = 1;
      d += step;
    }
    addRandom = true;
    if (outFile)
      path += FTEXT(".tmp");
    if (NFind::DoesFileOrDirExist(path))
    {
      SetLastError(ERROR_ALREADY_EXISTS);
      continue;
    }
    if (outFile)
    {
      if (outFile->Create(path, false))
        return true;
    }
    else
    {
      if (MyCreateDirectory(path))
        return true;
    }
    DWORD error = GetLastError();
    if (error != ERROR_FILE_EXISTS &&
        error != ERROR_ALREADY_EXISTS)
      break;
  }
  path.Empty();
  return false;
}
FString GetModuleDirPrefix()
{
  FString s;
  if (MyGetModuleFileName(s))
  {
    int pos = s.ReverseFind(FCHAR_PATH_SEPARATOR);
    if (pos >= 0)
    {
      s.DeleteFrom(pos + 1);
      return s;
    }
  }
  return FTEXT(".") FSTRING_PATH_SEPARATOR;
}
Exemple #6
0
int FTEXT(do_things)(LPCTSTR s) {
	int result = 0;
	FILE* f = NULL;
	f = _tfopen(FTEXT(coucou1), _T("rb"));
	if (f == NULL) {
		printf("Error(%d): %s\n", errno, strerror(errno));
		result = -1;
		goto cleanup;
	}

#ifdef _UNICODE
	printf("UNICODE\n");
#endif // _UNICODE

	_tprintf(_T("%s\n"), s);

cleanup:
	if (f) {
		fclose(f);
	}
	return result;
}
int CExtToIconMap::GetIconIndex(DWORD attrib, const wchar_t *fileName /*, UString *typeName */)
{
    int dotPos = -1;
    unsigned i;
    for (i = 0;; i++)
    {
        wchar_t c = fileName[i];
        if (c == 0)
            break;
        if (c == '.')
            dotPos = i;
    }

    /*
    if (MyStringCompareNoCase(fileName, L"$Recycle.Bin") == 0)
    {
      char s[256];
      sprintf(s, "SPEC i = %3d, attr = %7x", _attribMap.Size(), attrib);
      OutputDebugStringA(s);
      OutputDebugStringW(fileName);
    }
    */

    if ((attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 || dotPos < 0)
    {
        int insertPos = 0;
        int index = FindInSorted_Attrib(_attribMap, attrib, insertPos);
        if (index >= 0)
        {
            // if (typeName) *typeName = _attribMap[index].TypeName;
            return _attribMap[index].IconIndex;
        }
        CAttribIconPair pair;
        GetRealIconIndex(
#ifdef UNDER_CE
            FTEXT("\\")
#endif
            FTEXT("__DIR__")
            , attrib, pair.IconIndex
            // , pair.TypeName
        );

        /*
        char s[256];
        sprintf(s, "i = %3d, attr = %7x", _attribMap.Size(), attrib);
        OutputDebugStringA(s);
        */

        pair.Attrib = attrib;
        _attribMap.Insert(insertPos, pair);
        // if (typeName) *typeName = pair.TypeName;
        return pair.IconIndex;
    }

    const wchar_t *ext = fileName + dotPos + 1;
    int insertPos = 0;
    int index = FindInSorted_Ext(_extMap, ext, insertPos);
    if (index >= 0)
    {
        const CExtIconPair &pa = _extMap[index];
        // if (typeName) *typeName = pa.TypeName;
        return pa.IconIndex;
    }

    for (i = 0;; i++)
    {
        wchar_t c = ext[i];
        if (c == 0)
            break;
        if (c < L'0' || c > L'9')
            break;
    }
    if (i != 0 && ext[i] == 0)
    {
        // GetRealIconIndex is too slow for big number of split extensions: .001, .002, .003
        if (!SplitIconIndex_Defined)
        {
            GetRealIconIndex(
#ifdef UNDER_CE
                FTEXT("\\")
#endif
                FTEXT("__FILE__.001"), 0, SplitIconIndex);
            SplitIconIndex_Defined = true;
        }
        return SplitIconIndex;
    }

    CExtIconPair pair;
    pair.Ext = ext;
    GetRealIconIndex(us2fs(fileName + dotPos), attrib, pair.IconIndex);
    _extMap.Insert(insertPos, pair);
    // if (typeName) *typeName = pair.TypeName;
    return pair.IconIndex;
}
int WINAPI SevenZip(const HWND _hwnd, LPCSTR _szCmdLine, LPSTR _szOutput, const DWORD _dwSize)
{
	if (g_StdOut.GetThread())
		return g_StdOut.SetLastError(ERROR_ALREADY_RUNNING);

	CSplitCmdLine scl;
	if (!scl.Split(_szCmdLine))
		return g_StdOut.SetLastError(ERROR_COMMAND_NAME);

	NWindows::NFile::NDir::CTempFile sfxFile;
	if (scl.m_bSfx && scl.IsUpdateCommands())
	{
		CSfxDialog dlgSfx(_hwnd);
		if (dlgSfx.DoModal() == IDCANCEL)
			return g_StdOut.SetLastError(ERROR_USER_CANCEL);

		UInt32 sfxSize, processedSize;
		NWindows::NFile::NIO::COutFile file;
		sfxFile.CreateRandomInTempFolder(FTEXT("sfx"), &file);
		g_StdOut.SetSfxPath(sfxFile.GetPath());
		LPVOID lpResource = CSfxDialog::LoadSfxResource(sfxSize);
		file.Write(lpResource, sfxSize, processedSize);
		AString utf8String;
		ConvertUnicodeToUTF8(dlgSfx.GetConfigText(), utf8String);
		file.Write((const char*)utf8String, utf8String.Len(), processedSize);
		file.Close();
	}

	g_StdOut.SetCommandLine(scl);
	UString strCurrentDirectory;
	if (scl.m_lpBaseDirectory)
	{
		::NWindows::NFile::NDir::GetCurrentDir(strCurrentDirectory);
		if (::NWindows::NFile::NDir::SetCurrentDir(::MultiByteToUnicodeString(scl.m_lpBaseDirectory, scl.m_codePage)) == false)
		{
			g_StdOut << "Base directory isn't found.";
			g_StdOut.CopyBuf(_szOutput, _dwSize);
			g_StdOut.ReSet();
			return g_StdOut.SetLastError(ERROR_COMMAND_NAME);
		}
	}

	g_StdOut.CreateMainThread();

	CProgressDialog dlgProgress(_hwnd);
	g_StdOut.SetProgressDialog(&dlgProgress);
	dlgProgress.SetShowDialog(!scl.m_bHide);
	dlgProgress.SetProgressMode(scl.m_argv[0][0]);
	dlgProgress.CreateModal();

	DWORD dwThreadId;
	::WaitForSingleObject(g_StdOut.GetThread(), INFINITE);
	::GetExitCodeThread(g_StdOut.GetThread(), &dwThreadId);
	::CloseHandle(g_StdOut.GetThread());
	g_StdOut.CopyBuf(_szOutput, _dwSize);
	g_StdOut.ReSet();
	g_CodePage = -1;
	if (scl.m_lpBaseDirectory)
		::NWindows::NFile::NDir::SetCurrentDir(strCurrentDirectory);
    return dwThreadId;
}