Exemple #1
0
bool SearchAndLoadLanguageFile(
		const TCHAR* lpPath,
		const TCHAR* lpLanguage,
		TCHAR**& pStrings,
		int& nStringsCount
		)
{
	return FALSE; //BUGBUG

	bool bResult = false;

	TCHAR* lpMask = StrDuplicate(lpPath);
	CutToSlash (lpMask);

	_tcscat (lpMask, _T("*.lng"));

	WIN32_FIND_DATA FindData;

	HANDLE hSearch = FindFirstFile (
			lpMask,
			(WIN32_FIND_DATA*)&FindData
			);

	if ( hSearch != INVALID_HANDLE_VALUE )
	{
		do {

			CutToSlash (lpMask);
			_tcscat (lpMask, FindData.cFileName);

			pStrings = NULL;

			bResult = LoadLanguageFile(
					lpMask,
					lpLanguage,
					pStrings,
					nStringsCount
					);

		} while ( !bResult && FindNextFile (hSearch, (WIN32_FIND_DATA*)&FindData) );

		FindClose (hSearch);
	}

	StrFree(lpMask);

	return bResult;
}
Exemple #2
0
RarModule::RarModule (
		const char *lpFileName
		)
{
	char *lpModuleName = StrDuplicate(Info.ModuleName, 260);

	CutToSlash(lpModuleName);

	strcat (lpModuleName, "unrar.dll");

	m_hModule = LoadLibraryEx (
			lpModuleName,
			NULL,
			LOAD_WITH_ALTERED_SEARCH_PATH
			);

	StrFree (lpModuleName);

	if ( m_hModule )
	{
		m_pfnOpenArchiveEx = (RAROPENARCHIVEEX)GetProcAddress (m_hModule, "RAROpenArchiveEx");
		m_pfnCloseArchive = (RARCLOSEARCHIVE)GetProcAddress (m_hModule, "RARCloseArchive");
		m_pfnReadHeader = (RARREADHEADER)GetProcAddress (m_hModule, "RARReadHeader");
		m_pfnReadHeaderEx = (RARREADHEADEREX)GetProcAddress (m_hModule, "RARReadHeaderEx");
		m_pfnProcessFile = (RARPROCESSFILE)GetProcAddress (m_hModule, "RARProcessFile");
		m_pfnProcessFileW = (RARPROCESSFILEW)GetProcAddress (m_hModule, "RARProcessFileW");
		m_pfnSetCallback = (RARSETCALLBACK)GetProcAddress (m_hModule, "RARSetCallback");
		m_pfnSetProcessDataProc = (RARSETPROCESSDATAPROC)GetProcAddress (m_hModule, "RARSetProcessDataProc");
		m_pfnGetDllVersion = (RARGETDLLVERSION)GetProcAddress (m_hModule, "RARGetDllVersion");
		m_pfnSetPassword = (RARSETPASSWORD)GetProcAddress (m_hModule, "RARSetPassword");
	}
}
bool ObserverModule::Load()
{
	string strPluginsPath = Info.ModuleName;

	CutToSlash(strPluginsPath);
	strPluginsPath += _T("Formats");

	FSF.FarRecursiveSearch(strPluginsPath, _T("*.so"), (FRSUSERFUNC)LoadObserverPlugins, FRS_RECUR, this);

	m_pPluginInfo = new ArchivePluginInfo[m_Plugins.count()];

	for (unsigned int i = 0; i < m_Plugins.count(); i++)
	{
		ArchivePluginInfo* info = &m_pPluginInfo[i];
		memset(info, 0, sizeof(ArchivePluginInfo));

		ObserverPlugin* pPlugin = m_Plugins[i];

		info->uid = pPlugin->GetUID();
		info->lpModuleName = StrDuplicate(pPlugin->GetModuleName());
		info->uFormats = pPlugin->GetNumberOfFormats();
		info->pFormats = pPlugin->GetFormats();
		info->dwFlags = 0; //нет смысла поддерживать "запрос одного UID", все равно один плагин == один формат
	}

	return m_Plugins.count() > 0;
}
Exemple #4
0
/*
   Проверка пути или хост-файла на существование
   Если идет проверка пути (IsHostFile=FALSE), то будет
   предпринята попытка найти ближайший путь. Результат попытки
   возвращается в переданном TestPath.
*/
bool CheckShortcutFolder(string& pTestPath,int IsHostFile, BOOL Silent)
{
	if (!api::fs::exists(pTestPath))
	{
		int FoundPath=0;
		string strTarget = pTestPath;
		TruncPathStr(strTarget, ScrX-16);

		if (IsHostFile)
		{
			SetLastError(ERROR_FILE_NOT_FOUND);
			Global->CatchError();

			if (!Silent)
				Message(MSG_WARNING | MSG_ERRORTYPE, 1, MSG(MError), strTarget.data(), MSG(MOk));
		}
		else // попытка найти!
		{
			SetLastError(ERROR_PATH_NOT_FOUND);
			Global->CatchError();

			if (Silent || !Message(MSG_WARNING | MSG_ERRORTYPE, 2, MSG(MError), strTarget.data(), MSG(MNeedNearPath), MSG(MHYes),MSG(MHNo)))
			{
				string strTestPathTemp = pTestPath;

				for (;;)
				{
					if (!CutToSlash(strTestPathTemp,true))
						break;

					if (api::fs::exists(strTestPathTemp))
					{
						int ChkFld=TestFolder(strTestPathTemp);

						if (ChkFld == TSTFLD_EMPTY || ChkFld == TSTFLD_NOTEMPTY || ChkFld == TSTFLD_NOTACCESS)
						{
							if (!(pTestPath.size() > 1 && pTestPath[0] == L'\\' && pTestPath[1] == L'\\' && strTestPathTemp.size() == 1))
							{
								pTestPath = strTestPathTemp;

								if (pTestPath.size() == 2) // для случая "C:", иначе попадем в текущий каталог диска C:
									AddEndSlash(pTestPath);

								FoundPath=1;
							}

							break;
						}
					}
				}
			}
		}

		if (!FoundPath)
			return false;
	}

	return true;
}
Exemple #5
0
void ScanTree::SkipDir()
{
	if (!ScanItems.getCount())
		return;

	ScanItems.deleteItem(ScanItems.getCount()-1);

	if (!ScanItems.getCount())
		return;

	if (!ScanItems.lastItem()->Flags.Check(FSCANTREE_INSIDEJUNCTION))
		Flags.Clear(FSCANTREE_INSIDEJUNCTION);

	CutToSlash(strFindPath,true);
	CutToSlash(strFindPath);
	strFindPath += strFindMask;
}
Exemple #6
0
bool D5DModule::Load()
{
	string strPluginsPath = Info.ModuleName;

	CutToSlash(strPluginsPath);
	strPluginsPath += _T("Formats");

	FSF.FarRecursiveSearch(strPluginsPath, _T("*.d5d"), (FRSUSERFUNC)LoadD5DPlugins, FRS_RECUR, this);

	m_pPluginInfo = new ArchivePluginInfo[m_Plugins.count()];

	for (int i = 0; i < m_Plugins.count(); i++)
	{
		D5DPlugin* pPlugin = m_Plugins[i];
		ArchivePluginInfo* info = &m_pPluginInfo[i];

		info->dwFlags = 0;
		info->uid = pPlugin->GetUID();
		info->lpModuleName = StrDuplicate(pPlugin->GetModuleName());
		info->uFormats = pPlugin->GetNumberOfFormats();
		info->pFormats = pPlugin->GetFormats();
	}

	string strLanguageFilePath = Info.ModuleName;
	CutToSlash(strLanguageFilePath);

	string strLanguageFileName = strLanguageFilePath;

	string strLanguage;
	apiGetEnvironmentVariable(_T("FARLANG"), strLanguage);

	strLanguageFileName += strLanguage;
	strLanguageFileName += _T(".lng");

	if ( !lng.Load(strLanguageFileName) )
	{
		strLanguageFileName = strLanguageFilePath;
		strLanguageFileName += _T("english.lng");

		lng.Load(strLanguageFileName);
	}

	return (m_Plugins.count() > 0);
}
Exemple #7
0
int OnInitialize (StartupInfo *pInfo)
{
    Info = pInfo->Info;
	FSF = *pInfo->Info.FSF;

	char *lpModuleName = StrDuplicate(Info.ModuleName, 260);

	CutToSlash(lpModuleName);
    strcat (lpModuleName, "zlib.dll");
	InitZlib (lpModuleName);

	CutToSlash(lpModuleName);
	strcat (lpModuleName, "bzip2.dll");
	InitBlib (lpModuleName);

	StrFree (lpModuleName);

	return NAERROR_SUCCESS;
}
Exemple #8
0
bool AceModule::Load()
{
	bool bResult = false;

	m_pPlugin = new AcePlugin;

	if ( m_pPlugin )
	{
		string strModuleName = Info.ModuleName;

		CutToSlash(strModuleName);
		strModuleName += _T("unacev2.dll");

		if ( m_pPlugin->Load(strModuleName) )
			bResult = true;
		else
		{
			CutToSlash(strModuleName);
			strModuleName += _T("acev2.dll");

			if ( m_pPlugin->Load(strModuleName) )
				bResult = true;
		}
	}

	if ( bResult )
	{
		m_pPluginInfo = new ArchivePluginInfo;
		memset(m_pPluginInfo, 0, sizeof(ArchivePluginInfo));

		m_pPluginInfo->uid = m_pPlugin->GetUID();
		m_pPluginInfo->lpModuleName = StrDuplicate(m_pPlugin->GetModuleName());
		m_pPluginInfo->uFormats = m_pPlugin->GetNumberOfFormats();
		m_pPluginInfo->pFormats = m_pPlugin->GetFormats();
		m_pPluginInfo->dwFlags = APF_SUPPORT_SINGLE_FORMAT_QUERY;
	}

	return bResult;
}
Exemple #9
0
static void SetupFarPath(int argc, char **argv)
{
	InitCurrentDirectory();
	char buf[PATH_MAX + 1] = {};
	ssize_t buf_sz = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
	if (buf_sz <= 0 || buf_sz >= (ssize_t)sizeof(buf) - 1 || buf[0] != GOOD_SLASH) {
		if (argv[0][0]!=GOOD_SLASH) {
			apiGetCurrentDirectory(g_strFarModuleName);
			if (argv[0][0]=='.') {
				g_strFarModuleName+= argv[0] + 1;
			} else {
				g_strFarModuleName+= GOOD_SLASH;
				g_strFarModuleName+= argv[0];
			}
		} else
			g_strFarModuleName = argv[0];			
	} else {
		buf[buf_sz] = 0;
		g_strFarModuleName = buf;
	}
			
	

	FARString dir = g_strFarModuleName;
	CutToSlash(dir, true);
	const wchar_t *last_element = PointToName(dir);
	if (last_element && wcscmp(last_element, L"bin") == 0) {
		CutToSlash(dir, false);
		SetPathTranslationPrefix(dir);
	}

	fprintf(stderr, "argv[0]='%s' g_strFarModuleName='%ls' translation_prefix='%ls'\n", 
		argv[0], g_strFarModuleName.CPtr(), GetPathTranslationPrefix());

	PrepareDiskPath(g_strFarModuleName);
}
void ArchivePlugin::ReloadLanguage (
		const char *lpLanguage
		)
{
	FinalizeLanguageStrings (m_pLanguageStrings, m_nStringsCount);

	char *lpPath = StrDuplicate (m_lpModuleName);

	CutToSlash (lpPath);

	if ( !SearchAndLoadLanguageFile (lpPath, lpLanguage, m_pLanguageStrings, m_nStringsCount) )
		if ( !SearchAndLoadLanguageFile(lpPath, "English", m_pLanguageStrings, m_nStringsCount) )
			SearchAndLoadLanguageFile (lpPath, NULL, m_pLanguageStrings, m_nStringsCount);

	StrFree (lpPath);
}
Exemple #11
0
void FilePanels::GoToFile(const wchar_t *FileName)
{
	if (FirstSlash(FileName))
	{
		string ADir,PDir;
		Panel *PassivePanel = GetAnotherPanel(ActivePanel);
		int PassiveMode = PassivePanel->GetMode();

		if (PassiveMode == NORMAL_PANEL)
		{
			PassivePanel->GetCurDir(PDir);
			AddEndSlash(PDir);
		}

		int ActiveMode = ActivePanel->GetMode();

		if (ActiveMode==NORMAL_PANEL)
		{
			ActivePanel->GetCurDir(ADir);
			AddEndSlash(ADir);
		}

		string strNameFile = PointToName(FileName);
		string strNameDir = FileName;
		CutToSlash(strNameDir);
		/* $ 10.04.2001 IS
		     Не делаем SetCurDir, если нужный путь уже есть на открытых
		     панелях, тем самым добиваемся того, что выделение с элементов
		     панелей не сбрасывается.
		*/
		BOOL AExist=(ActiveMode==NORMAL_PANEL) && !StrCmpI(ADir,strNameDir);
		BOOL PExist=(PassiveMode==NORMAL_PANEL) && !StrCmpI(PDir,strNameDir);

		// если нужный путь есть на пассивной панели
		if (!AExist && PExist)
			ProcessKey(KEY_TAB);

		if (!AExist && !PExist)
			ActivePanel->SetCurDir(strNameDir,TRUE);

		ActivePanel->GoToFile(strNameFile);
		// всегда обновим заголовок панели, чтобы дать обратную связь, что
		// Ctrl-F10 обработан
		ActivePanel->SetTitle();
	}
}
Exemple #12
0
int DeleteFileWithFolder(const string& FileName)
{
	string strFileOrFolderName;
	strFileOrFolderName = FileName;
	Unquote(strFileOrFolderName);
	BOOL Ret=apiSetFileAttributes(strFileOrFolderName,FILE_ATTRIBUTE_NORMAL);

	if (Ret)
	{
		if (apiDeleteFile(strFileOrFolderName)) //BUGBUG
		{
			CutToSlash(strFileOrFolderName,true);
			return apiRemoveDirectory(strFileOrFolderName);
		}
	}

	return FALSE;
}
bool ArchiveModuleManager::LoadIfNeeded()
{
	if ( !m_bLoaded )
	{
		string strModulesPath = Info.ModuleName;

		CutToSlash(strModulesPath);
		strModulesPath += _T("Modules"); 

		FSF.FarRecursiveSearch(strModulesPath, _T("*.module"), (FRSUSERFUNC)LoadModules, FRS_RECUR, this);

		m_pConfig->Load();

		m_bLoaded = true;
	}

	return m_bLoaded;
}
Exemple #14
0
int FileList::FileNameToPluginItem(const string& Name,PluginPanelItem *pi)
{
	string strTempDir = Name;

	if (!CutToSlash(strTempDir,true))
		return FALSE;

	FarChDir(strTempDir);
	ClearStruct(*pi);
	FAR_FIND_DATA_EX fdata;

	if (apiGetFindDataEx(Name, fdata))
	{
		FindDataExToPluginPanelItem(&fdata, pi);
		return TRUE;
	}

	return FALSE;
}
Exemple #15
0
static int WipeDirectory(const string& Name)
{
	string strTempName, strPath;

	if (FirstSlash(Name.data()))
	{
		strPath = Name;
		DeleteEndSlash(strPath);
		CutToSlash(strPath);
	}

	FarMkTempEx(strTempName,nullptr, FALSE, strPath.empty()?nullptr:strPath.data());

	if (!os::MoveFile(Name, strTempName))
	{
		return FALSE;
	}

	return os::RemoveDirectory(strTempName);
}
Exemple #16
0
int WipeDirectory(const string& Name)
{
	string strTempName, strPath;

	if (FirstSlash(Name))
	{
		strPath = Name;
		DeleteEndSlash(strPath);
		CutToSlash(strPath);
	}

	FarMkTempEx(strTempName,nullptr, FALSE, strPath.IsEmpty()?nullptr:strPath.CPtr());

	if (!apiMoveFile(Name, strTempName))
	{
		return FALSE;
	}

	return apiRemoveDirectory(strTempName);
}
Exemple #17
0
void QuickView::QViewDelTempName()
{
	if (m_TemporaryFile)
	{
		if (QView)
		{
			LastWrapMode=QView->GetWrapMode();
			LastWrapType=QView->GetWrapType();
			QView->SetWrapMode(OldWrapMode);
			QView->SetWrapType(OldWrapType);
			QView=nullptr;
		}

		os::SetFileAttributes(strCurFileName, FILE_ATTRIBUTE_ARCHIVE);
		os::DeleteFile(strCurFileName);  //BUGBUG
		string TempDirectoryName = strCurFileName;
		CutToSlash(TempDirectoryName);
		os::RemoveDirectory(TempDirectoryName);
		m_TemporaryFile = false;
	}
}
Exemple #18
0
int WipeDirectory(const wchar_t *Name)
{
	string strTempName, strPath;

	if (FirstSlash(Name))
	{
		strPath = Name;
		DeleteEndSlash(strPath);
		CutToSlash(strPath);
	}

	FarMkTempEx(strTempName,nullptr, FALSE, strPath.IsEmpty()?nullptr:strPath.CPtr());

	if (!apiMoveFile(Name, strTempName))
	{
		SetLastError((_localLastError = GetLastError()));
		return FALSE;
	}

	return apiRemoveDirectory(strTempName);
}
Exemple #19
0
static BOOL PrepareModulePath(const string& ModuleName)
{
	string strModulePath = ModuleName;
	CutToSlash(strModulePath); //??
	return FarChDir(strModulePath);
}
Exemple #20
0
bool MaModule::Load()
{
	string strPluginsPath = Info.ModuleName;

#ifdef UNICODE
	CutToSlash(strPluginsPath);

	strPluginsPath += _T("ansi.dll");

	bool bAnsiModuleLoaded = false;
	GETPLUGINSSTARTUPINFO pfnGetPluginStartupInfo = nullptr;



	if ( Info.PluginsControl(
			INVALID_HANDLE_VALUE, 
			2/*PCTL_FORCEDLOADPLUGIN*/,  //BUGBUG
			PLT_PATH, 
			(LONG_PTR)strPluginsPath.GetString()
			) )
	{
		HMODULE hAnsiModule = LoadLibraryEx(
				strPluginsPath, 
				NULL, 
				LOAD_WITH_ALTERED_SEARCH_PATH
				);

		if ( hAnsiModule )
		{
			pfnGetPluginStartupInfo = (GETPLUGINSSTARTUPINFO)GetProcAddress(hAnsiModule, "GetPluginStartupInfo");

			if ( pfnGetPluginStartupInfo && pfnGetPluginStartupInfo(&m_pInfo, &m_pFSF) )
				bAnsiModuleLoaded = true;

			FreeLibrary(hAnsiModule);
		}
	}

	if ( !bAnsiModuleLoaded )
	{
		__debug(pfnGetPluginStartupInfo ? _T("ansi.dll was not loaded before ma.module") : _T("error with ansi.dll"));
		return false;
	}

#else
	m_pInfo = (oldfar::PluginStartupInfo*)&Info;
	m_pFSF = (oldfar::FARSTANDARDFUNCTIONS*)&FSF;
#endif


	CutToSlash(strPluginsPath);
	strPluginsPath += _T("Formats");

	FSF.FarRecursiveSearch(strPluginsPath, _T("*.fmt"), (FRSUSERFUNC)LoadMaPlugins, FRS_RECUR, this);

	m_pPluginInfo = new ArchivePluginInfo[m_Plugins.count()];

	for (unsigned int i = 0; i < m_Plugins.count(); i++)
	{
		MaPlugin *pPlugin = m_Plugins[i];
		ArchivePluginInfo *info = &m_pPluginInfo[i];

		info->uid = pPlugin->GetUID();
		info->uFormats = pPlugin->GetNumberOfFormats();
		info->pFormats = pPlugin->GetFormats();
		info->lpModuleName = StrDuplicate(pPlugin->GetModuleName());
		info->dwFlags = 0; //не поддерживаем запрос отдельных форматов
	}

	return m_Plugins.count() > 0;
}
Exemple #21
0
bool Panel::ExecShortcutFolder(string strShortcutFolder, const GUID& PluginGuid, const string& strPluginFile, const string& strPluginData, bool CheckType, bool TryClosest, bool Silent)
{
	auto SrcPanel = shared_from_this();
	const auto AnotherPanel = Parent()->GetAnotherPanel(this);

	if(CheckType)
	{
		switch (GetType())
		{
		case panel_type::FILE_PANEL:
			break;

		case panel_type::TREE_PANEL:
		case panel_type::QVIEW_PANEL:
		case panel_type::INFO_PANEL:
			if (AnotherPanel->GetType() == panel_type::FILE_PANEL)
				SrcPanel=AnotherPanel;
			break;
		}
	}

	bool CheckFullScreen=SrcPanel->IsFullScreen();

	if (PluginGuid != FarGuid)
	{
		bool Result = false;
		ShortcutInfo Info;
		GetShortcutInfo(Info);
		if (Info.PluginGuid == PluginGuid && Info.PluginFile == strPluginFile && Info.PluginData == strPluginData)
		{
			Result = SetPluginDirectory(strShortcutFolder, Silent);
		}
		else
		{
			if (ProcessPluginEvent(FE_CLOSE, nullptr))
			{
				return false;
			}

			if (const auto pPlugin = Global->CtrlObject->Plugins->FindPlugin(PluginGuid))
			{
				if (pPlugin->has(iOpen))
				{
					if (!strPluginFile.empty())
					{
						auto strRealDir = strPluginFile;
						if (CutToSlash(strRealDir))
						{
							SrcPanel->SetCurDir(strRealDir,true);
							SrcPanel->GoToFile(PointToName(strPluginFile));

							SrcPanel->ClearAllItem();
						}
					}

					const auto IsActive = SrcPanel->IsFocused();
					OpenShortcutInfo info=
					{
						sizeof(OpenShortcutInfo),
						strPluginFile.empty()? nullptr : strPluginFile.c_str(),
						strPluginData.empty()? nullptr : strPluginData.c_str(),
						IsActive? FOSF_ACTIVE : FOSF_NONE
					};

					if (auto hNewPlugin = Global->CtrlObject->Plugins->Open(pPlugin, OPEN_SHORTCUT, FarGuid, reinterpret_cast<intptr_t>(&info)))
					{
						const auto NewPanel = Parent()->ChangePanel(SrcPanel, panel_type::FILE_PANEL, TRUE, TRUE);
						NewPanel->SetPluginMode(std::move(hNewPlugin), {}, IsActive || !Parent()->GetAnotherPanel(NewPanel)->IsVisible());
						Result = NewPanel->SetPluginDirectory(strShortcutFolder, Silent);
					}
				}
			}
		}
		return Result;
	}

	strShortcutFolder = os::env::expand(strShortcutFolder);

	if (!CheckShortcutFolder(strShortcutFolder, TryClosest, Silent) || ProcessPluginEvent(FE_CLOSE, nullptr))
	{
		return false;
	}

	SrcPanel->SetCurDir(strShortcutFolder,true);

	if (CheckFullScreen!=SrcPanel->IsFullScreen())
		Parent()->GetAnotherPanel(SrcPanel)->Show();

	SrcPanel->Refresh();
	return true;
}
Exemple #22
0
void ArchiveModule::ReloadLanguage(
		const TCHAR* lpLanguage
		)
{
	string strPath = m_strModuleName;
	CutToSlash (strPath);

	Language* pLanguage = nullptr;
	Language* pEnglishLanguage = nullptr;

	string strMask = strPath+_T("*.lng");
	
	WIN32_FIND_DATA FindData;
	bool bResult = false;

	HANDLE hSearch = FindFirstFile(
			strMask,
			(WIN32_FIND_DATA*)&FindData
			);

	if ( hSearch != INVALID_HANDLE_VALUE )
	{
		do {
			string strFileName = strPath+FindData.cFileName;

			pLanguage = new Language();

			if ( pLanguage->LoadFromFile(strFileName) )
			{
				string strLanguage = pLanguage->GetLanguage();

				if ( strLanguage == lpLanguage )
				{
					if ( m_pLanguage )
						delete m_pLanguage;

					m_pLanguage = pLanguage;

					bResult = true;
				}
				else
				{
					if ( strLanguage == _T("English") ) //case??
					{
						if ( !pEnglishLanguage ) //нам два не надо
							pEnglishLanguage = pLanguage;
						else
							delete pLanguage;
					}
					else
						delete pLanguage;
				}
			}
			else
				delete pLanguage;

		} while ( !bResult && FindNextFile(hSearch, (WIN32_FIND_DATA*)&FindData) );

		FindClose (hSearch);
	}

	if ( pEnglishLanguage )
	{
		if ( !bResult )
		{
			if ( m_pLanguage )
				delete m_pLanguage;

			m_pLanguage = pEnglishLanguage;
		}
		else
			delete pEnglishLanguage;
	}
}
Exemple #23
0
int FarAppMain(int argc, char **argv)
{

	Opt.IsUserAdmin = (geteuid()==0);

	_OT(SysLog(L"[[[[[[[[New Session of FAR]]]]]]]]]"));
	FARString strEditName;
	FARString strViewName;
	FARString DestNames[2];
	int StartLine=-1,StartChar=-1;
	int CntDestName=0; // количество параметров-имен каталогов
	/*$ 18.04.2002 SKV
	  Попользуем floating point что бы проинициализировался vc-ный fprtl.
	*/
#ifdef _MSC_VER
	float x=1.1f;
	wchar_t buf[15];
	swprintf(buf,L"%f",x);
#endif
	// если под дебагером, то отключаем исключения однозначно,
	//  иначе - смотря что указал юзвер.
#if defined(_DEBUGEXC)
	Opt.ExceptRules=-1;
#else
	Opt.ExceptRules=-1;//IsDebuggerPresent()?0:-1;
#endif
//  Opt.ExceptRules=-1;

#ifdef __GNUC__
	Opt.ExceptRules=0;
#endif

//_SVS(SysLog(L"Opt.ExceptRules=%d",Opt.ExceptRules));
	SetRegRootKey(HKEY_CURRENT_USER);
	Opt.strRegRoot = L"Software/Far2";
	// По умолчанию - брать плагины из основного каталога
	Opt.LoadPlug.MainPluginDir=TRUE;
	Opt.LoadPlug.PluginsPersonal=TRUE;
	Opt.LoadPlug.PluginsCacheOnly=FALSE;

	g_strFarPath = g_strFarModuleName;

	bool translated = TranslateFarString<TranslateInstallPath_Bin2Share>(g_strFarPath);
	CutToSlash(g_strFarPath, true);
	if (translated) {
		// /usr/bin/something -> /usr/share/far2l
		g_strFarPath+= L"/" FAR_BASENAME;
	}
		
	WINPORT(SetEnvironmentVariable)(L"FARHOME", g_strFarPath);
	AddEndSlash(g_strFarPath);

	// don't inherit from parent process in any case
	WINPORT(SetEnvironmentVariable)(L"FARUSER", nullptr);

	WINPORT(SetEnvironmentVariable)(L"FARADMINMODE", Opt.IsUserAdmin?L"1":nullptr);

	// макросы не дисаблим
	Opt.Macro.DisableMacro=0;
	for (int I=1; I<argc; I++)
	{
		std::wstring arg_w = MB2Wide(argv[I]);
		if ((arg_w[0]==L'/' || arg_w[0]==L'-') && arg_w[1])
		{
			switch (Upper(arg_w[1]))
			{
				case L'A':

					switch (Upper(arg_w[2]))
					{
						case 0:
							Opt.CleanAscii=TRUE;
							break;
						case L'G':

							if (!arg_w[3])
								Opt.NoGraphics=TRUE;

							break;
					}

					break;
				case L'E':

					if (iswdigit(arg_w[2]))
					{
						StartLine=_wtoi((const wchar_t *)&arg_w[2]);
						wchar_t *ChPtr=wcschr((wchar_t *)&arg_w[2],L':');

						if (ChPtr)
							StartChar=_wtoi(ChPtr+1);
					}

					if (I+1<argc)
					{
						strEditName = argv[I+1];
						I++;
					}

					break;
				case L'V':

					if (I+1<argc)
					{
						strViewName = argv[I+1];
						I++;
					}

					break;
				case L'M':

					switch (Upper(arg_w[2]))
					{
						case 0:
							Opt.Macro.DisableMacro|=MDOL_ALL;
							break;
						case L'A':

							if (!arg_w[3])
								Opt.Macro.DisableMacro|=MDOL_AUTOSTART;

							break;
					}

					break;
				case L'I':
					Opt.SmallIcon=TRUE;
					break;
				case L'X':
					Opt.ExceptRules=0;
#if defined(_DEBUGEXC)

					if (Upper(arg_w[2])==L'D' && !arg_w[3])
						Opt.ExceptRules=1;

#endif
					break;

				case L'C':

					if (Upper(arg_w[2])==L'O' && !arg_w[3])
					{
						Opt.LoadPlug.PluginsCacheOnly=TRUE;
						Opt.LoadPlug.PluginsPersonal=FALSE;
					}

					break;
				case L'?':
				case L'H':
					ControlObject::ShowCopyright(1);
					show_help();
					return 0;
#ifdef DIRECT_RT
				case L'D':

					if (Upper(arg_w[2])==L'O' && !arg_w[3])
						DirectRT=1;

					break;
#endif
				case L'W':
					{
						Opt.WindowMode=TRUE;
					}
					break;
			}
		}
		else // простые параметры. Их может быть max две штукА.
		{
			if (CntDestName < 2)
			{
				if (IsPluginPrefixPath((const wchar_t *)arg_w.c_str()))
				{
					DestNames[CntDestName++] = (const wchar_t *)arg_w.c_str();
				}
				else
				{
					apiExpandEnvironmentStrings((const wchar_t *)arg_w.c_str(), DestNames[CntDestName]);
					Unquote(DestNames[CntDestName]);
					ConvertNameToFull(DestNames[CntDestName],DestNames[CntDestName]);

					if (apiGetFileAttributes(DestNames[CntDestName]) != INVALID_FILE_ATTRIBUTES)
						CntDestName++; //???
				}
			}
		}
	}

	//Настройка OEM сортировки. Должна быть после CopyGlobalSettings и перед InitKeysArray!
	//LocalUpperInit();
	//InitLCIDSort();
	//Инициализация массива клавиш. Должна быть после CopyGlobalSettings!
	InitKeysArray();
	//WaitForInputIdle(GetCurrentProcess(),0);
	std::set_new_handler(nullptr);

	if (!Opt.LoadPlug.MainPluginDir) //если есть ключ /p то он отменяет /co
		Opt.LoadPlug.PluginsCacheOnly=FALSE;

	if (Opt.LoadPlug.PluginsCacheOnly)
	{
		Opt.LoadPlug.strCustomPluginsPath.Clear();
		Opt.LoadPlug.MainPluginDir=FALSE;
		Opt.LoadPlug.PluginsPersonal=FALSE;
	}

	InitConsole();
	GetRegKey(L"Language",L"Main",Opt.strLanguage,L"English");

	if (!Lang.Init(g_strFarPath,true,MNewFileName))
	{
		ControlObject::ShowCopyright(1);
		LPCWSTR LngMsg;
		switch(Lang.GetLastError())
		{
		case LERROR_BAD_FILE:
			LngMsg = L"\nError: language data is incorrect or damaged.\n\nPress any key to exit...";
			break;
		case LERROR_FILE_NOT_FOUND:
			LngMsg = L"\nError: cannot find language data.\n\nPress any key to exit...";
			break;
		default:
			LngMsg = L"\nError: cannot load language data.\n\nPress any key to exit...";
			break;
		}
		Console.Write(LngMsg,StrLength(LngMsg));
		Console.FlushInputBuffer();
		WaitKey(); // А стоит ли ожидать клавишу??? Стоит
		return 1;
	}

	WINPORT(SetEnvironmentVariable)(L"FARLANG",Opt.strLanguage);
	SetHighlighting();
	initMacroVarTable(1);

	if (Opt.ExceptRules == -1)
	{
		GetRegKey(L"System",L"ExceptRules",Opt.ExceptRules,1);
	}

	//ErrorMode=SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX|(Opt.ExceptRules?SEM_NOGPFAULTERRORBOX:0)|(GetRegKey(L"System/Exception", L"IgnoreDataAlignmentFaults", 0)?SEM_NOALIGNMENTFAULTEXCEPT:0);
	//SetErrorMode(ErrorMode);

	int Result=MainProcessSEH(strEditName,strViewName,DestNames[0],DestNames[1],StartLine,StartChar);

	EmptyInternalClipboard();
	doneMacroVarTable(1);
	VTShell_Shutdown();//ensure VTShell deinitialized before statics destructors called
	_OT(SysLog(L"[[[[[Exit of FAR]]]]]]]]]"));
	return Result;
}
Exemple #24
0
int ExecuteCommand(Archive* pArchive, void* pParam)
{
	ExecuteStruct* pES = (ExecuteStruct*)pParam;

	int nResult = RESULT_ERROR;

	ParamStruct psParam;
	FarPanelInfo info;
		
	TCHAR* lpTempPath = psParam.strTempPath.GetBuffer(260);
	GetTempPath (260, lpTempPath);
	psParam.strTempPath.ReleaseBuffer();

	TCHAR* lpListFileName = psParam.strListFileName.GetBuffer(260);
#ifdef UNICODE
	FSF.MkTemp (lpListFileName, 260, _T("NALT"));
#else
	FSF.MkTemp (lpListFileName, _T("NALT"));
#endif
	psParam.strListFileName.ReleaseBuffer();

	string strFileName = pArchive->GetFileName();
	string strPath;
		
	if ( pES->lpCurrentDiskPath )
		strPath = pES->lpCurrentDiskPath;
	else
	{
		strPath = strFileName;
		CutToSlash(strPath);
	}

	QuoteSpaceOnly(psParam.strTempPath);
	QuoteSpaceOnly(psParam.strListFileName);
	QuoteSpaceOnly(strFileName);
		
	psParam.strArchiveName = strFileName;
	psParam.strShortArchiveName = strFileName;
	psParam.strPassword = pES->lpPassword;
	psParam.strPathInArchive = pArchive->GetCurrentDirectory();
	psParam.strAdditionalCommandLine = pES->lpAdditionalCommandLine;

	string strExecuteString;
	int nStartItemNumber = 0;

	while ( true )
	{
		int nParseResult = ParseString(
				pES->items,
				pES->lpCommand,
				strExecuteString,
				&psParam,
				nStartItemNumber
				);

		if ( (nParseResult == PE_SUCCESS) || (nParseResult == PE_MORE_FILES) )
		{
			PROCESS_INFORMATION pInfo;
			STARTUPINFO sInfo;

			memset (&sInfo, 0, sizeof (STARTUPINFO));
			sInfo.cb = sizeof (STARTUPINFO);

			apiExpandEnvironmentStrings(strExecuteString, strExecuteString);

			HANDLE hScreen = Info.SaveScreen(0, 0, -1, -1);

#ifdef UNICODE
			Info.Control(INVALID_HANDLE_VALUE, FCTL_GETUSERSCREEN, 0, 0);
#else
			Info.Control(INVALID_HANDLE_VALUE, FCTL_GETUSERSCREEN, 0);
#endif
			if ( CreateProcess (
					NULL,
					strExecuteString.GetBuffer(),
					NULL,
					NULL,
					TRUE,
					0,
					NULL,
					strPath, 
					&sInfo,
					&pInfo
					) )
			{
				WaitForSingleObject(pInfo.hProcess, INFINITE);

				DWORD dwExitCode;
				GetExitCodeProcess(pInfo.hProcess, &dwExitCode);

				CloseHandle (pInfo.hProcess);
				CloseHandle (pInfo.hThread);

				nResult = (dwExitCode == 0)?RESULT_SUCCESS:RESULT_ERROR;
			}
			else
			{
				string strError;
				strError.Format(_T("CreateProcess failed - %d\n%s"), GetLastError(), strExecuteString.GetString());
				msgError(strError);
			}

#ifdef UNICODE
			Info.Control(INVALID_HANDLE_VALUE, FCTL_SETUSERSCREEN, 0, 0);
#else
			Info.Control(INVALID_HANDLE_VALUE, FCTL_SETUSERSCREEN, 0);
#endif

			Info.RestoreScreen(NULL);
			Info.RestoreScreen(hScreen);
		}

		if ( nParseResult != PE_MORE_FILES )
			break;
	}
		
	DeleteFile (psParam.strListFileName); //WARNING!!!

	return nResult;
}
Exemple #25
0
bool ScanTree::GetNextName(FAR_FIND_DATA_EX *fdata,string &strFullName)
{
	if (!ScanItems.getCount())
		return false;

	bool Done=false;
	Flags.Clear(FSCANTREE_SECONDDIRNAME);

	for (;;)
	{
		ScanTreeData* LastItem = ScanItems.lastItem();
		if (!LastItem->Find)
		{
			LastItem->Find = new FindFile(strFindPath);
		}
		Done=!LastItem->Find->Get(*fdata);

		if (Flags.Check(FSCANTREE_FILESFIRST))
		{
			if (LastItem->Flags.Check(FSCANTREE_SECONDPASS))
			{
				if (!Done && !(fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
					continue;
			}
			else
			{
				if (!Done && (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
					continue;

				if (Done)
				{
					if(LastItem->Find)
					{
						delete LastItem->Find;
						LastItem->Find = nullptr;
					}
					LastItem->Flags.Set(FSCANTREE_SECONDPASS);
					continue;
				}
			}
		}
		break;
	}

	if (Done)
	{
		ScanItems.deleteItem(ScanItems.getCount()-1);

		if (!ScanItems.getCount())
			return false;
		else
		{
			if (ScanItems.lastItem()->Flags.Check(FSCANTREE_INSIDEJUNCTION))
				Flags.Clear(FSCANTREE_INSIDEJUNCTION);

			CutToSlash(strFindPath,true);

			if (Flags.Check(FSCANTREE_RETUPDIR))
			{
				strFullName = strFindPath;
				apiGetFindDataEx(strFullName, *fdata);
			}

			CutToSlash(strFindPath);
			strFindPath += strFindMask;
			_SVS(SysLog(L"1. FullName='%s'",strFullName.CPtr()));

			if (Flags.Check(FSCANTREE_RETUPDIR))
			{
				Flags.Set(FSCANTREE_SECONDDIRNAME);
				return true;
			}

			return GetNextName(fdata,strFullName);
		}
	}
	else
	{
		if ((fdata->dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) && Flags.Check(FSCANTREE_RECUR) &&
		        (!(fdata->dwFileAttributes&FILE_ATTRIBUTE_REPARSE_POINT) || Flags.Check(FSCANTREE_SCANSYMLINK)))
		{
			string RealPath(ScanItems.lastItem()->RealPath);
			AddEndSlash(RealPath);
			RealPath += fdata->strFileName;

			if (fdata->dwFileAttributes&FILE_ATTRIBUTE_REPARSE_POINT)
				ConvertNameToReal(RealPath, RealPath);

			//recursive symlinks guard
			bool Recursion = false;

			for (size_t i = 0; i < ScanItems.getCount() && !Recursion; i++)
				Recursion = ScanItems.getItem(i)->RealPath == RealPath;

			if (!Recursion)
			{
				CutToSlash(strFindPath);
				strFindPath += fdata->strFileName;
				strFullName = strFindPath;
				strFindPath += L"\\";
				strFindPath += strFindMask;
				ScanItems.addItem();
				ScanItems.lastItem()->Flags = ScanItems.getItem(ScanItems.getCount()-2)->Flags; // наследуем флаг
				ScanItems.lastItem()->Flags.Clear(FSCANTREE_SECONDPASS);
				ScanItems.lastItem()->RealPath = RealPath;

				if (fdata->dwFileAttributes&FILE_ATTRIBUTE_REPARSE_POINT)
				{
					ScanItems.lastItem()->Flags.Set(FSCANTREE_INSIDEJUNCTION);
					Flags.Set(FSCANTREE_INSIDEJUNCTION);
				}

				return true;
			}
		}
	}

	strFullName = strFindPath;
	CutToSlash(strFullName);
	strFullName += fdata->strFileName;
	return true;
}
Exemple #26
0
// Кусок для создания SymLink для каталогов.
int MkSymLink(const string& Target, const string& LinkName, ReparsePointTypes LinkType, bool Silent, bool HoldTarget)
{
	if (!Target.empty() && !LinkName.empty())
	{
		string strFullTarget;
		// выделим имя
		auto strSelOnlyName = Target;
		DeleteEndSlash(strSelOnlyName);
		const auto SlashPos = FindLastSlash(strSelOnlyName);

		const auto symlink = LinkType==RP_SYMLINK || LinkType==RP_SYMLINKFILE || LinkType==RP_SYMLINKDIR;

		if (Target[1] == L':' && (!Target[2] || (IsSlash(Target[2]) && !Target[3]))) // C: или C:/
		{
//      if(Flags&FCOPY_VOLMOUNT)
			{
				strFullTarget = Target;
				AddEndSlash(strFullTarget);
			}
			/*
			  Вот здесь - ну очень умное поведение!
			  Т.е. если в качестве SelName передали "C:", то в этом куске происходит
			  коррекция типа линка - с symlink`а на volmount
			*/
			LinkType=RP_VOLMOUNT;
		}
		else
			strFullTarget = ConvertNameToFull(Target);

		auto strFullLink = ConvertNameToFull(LinkName);

		if (IsSlash(strFullLink.back()))
		{
			if (LinkType != RP_VOLMOUNT)
			{
				const auto SelName = SlashPos != string::npos? string_view(strSelOnlyName).substr(SlashPos + 1) : string_view(strSelOnlyName);
				append(strFullLink, SelName);
			}
			else
			{
				append(strFullLink, L"Disk_"sv, Target.front());
			}
		}

		if (LinkType==RP_VOLMOUNT)
		{
			AddEndSlash(strFullTarget);
			AddEndSlash(strFullLink);
		}

			if (symlink)
			{
				// в этом случае создается путь, но не сам каталог
				string strPath=strFullLink;

				if (CutToSlash(strPath))
				{
					if (!os::fs::exists(strPath))
						CreatePath(strPath);
				}
			}
			else
			{
				bool CreateDir=true;

				if (LinkType==RP_EXACTCOPY)
				{
					// в этом случае создается или каталог, или пустой файл
					if (os::fs::is_file(strFullTarget))
						CreateDir=false;
				}

				if (CreateDir)
				{
					if (os::fs::create_directory(strFullLink))
						TreeList::AddTreeName(strFullLink);
					else
						CreatePath(strFullLink);
				}
				else
				{
					string strPath=strFullLink;

					if (CutToSlash(strPath))
					{
						if (!os::fs::exists(strPath))
							CreatePath(strPath);
						os::fs::file(strFullLink, 0, 0, nullptr, CREATE_NEW, os::fs::get_file_attributes(strFullTarget));
					}
				}

				if (!os::fs::exists(strFullLink))
				{
					if (!Silent)
					{
						const auto ErrorState = error_state::fetch();

						Message(MSG_WARNING, ErrorState,
							msg(lng::MError),
							{
								msg(lng::MCopyCannotCreateLink),
								strFullLink
							},
							{ lng::MOk });
					}

					return 0;
				}
			}

		if (LinkType!=RP_VOLMOUNT)
		{
			if (CreateReparsePoint(HoldTarget && symlink ? Target : strFullTarget, strFullLink, LinkType))
			{
				return 1;
			}
			else
			{
				if (!Silent)
				{
					const auto ErrorState = error_state::fetch();

					Message(MSG_WARNING, ErrorState,
						msg(lng::MError),
						{
							msg(lng::MCopyCannotCreateLink),
							strFullLink
						},
						{ lng::MOk });
				}

				return 0;
			}
		}
		else
		{
			if (CreateVolumeMountPoint(strFullTarget,strFullLink))
			{
				return 1;
			}
			else
			{
				if (!Silent)
				{
					const auto ErrorState = error_state::fetch();

					Message(MSG_WARNING, ErrorState,
						msg(lng::MError),
						{
							format(msg(lng::MCopyMountVolFailed), Target),
							format(msg(lng::MCopyMountVolFailed2), strFullLink)
						},
						{ lng::MOk });
				}

				return 0;
			}
		}
	}

	return 2;
}
Exemple #27
0
// Кусок для создания SymLink для каталогов.
int MkSymLink(const wchar_t *SelName,const wchar_t *Dest,ReparsePointTypes LinkType,DWORD Flags)
{
	if (SelName && *SelName && Dest && *Dest)
	{
		string strSrcFullName, strDestFullName, strSelOnlyName;
		string strMsgBuf, strMsgBuf2;
		// выделим имя
		strSelOnlyName = SelName;
		DeleteEndSlash(strSelOnlyName);
		const wchar_t *PtrSelName=LastSlash(strSelOnlyName);

		if (!PtrSelName)
			PtrSelName=strSelOnlyName;
		else
			++PtrSelName;

		if (SelName[1] == L':' && (!SelName[2] || (IsSlash(SelName[2]) && !SelName[3]))) // C: или C:/
		{
//      if(Flags&FCOPY_VOLMOUNT)
			{
				strSrcFullName = SelName;
				AddEndSlash(strSrcFullName);
			}
			/*
			  Вот здесь - ну очень умное поведение!
			  Т.е. если в качестве SelName передали "C:", то в этом куске происходит
			  коррекция типа линка - с symlink`а на volmount
			*/
			LinkType=RP_VOLMOUNT;
		}
		else
			ConvertNameToFull(SelName,strSrcFullName);

		ConvertNameToFull(Dest,strDestFullName);

		if (IsSlash(strDestFullName.At(strDestFullName.GetLength()-1)))
		{
			if (LinkType!=RP_VOLMOUNT)
				strDestFullName += PtrSelName;
			else
			{
				const wchar_t Tmp[]={L'D',L'i',L's',L'k',L'_',*SelName,L'\0'};
				strDestFullName+=Tmp;
			}
		}

		if (LinkType==RP_VOLMOUNT)
		{
			AddEndSlash(strSrcFullName);
			AddEndSlash(strDestFullName);
		}

		DWORD JSAttr=apiGetFileAttributes(strDestFullName);

		if (JSAttr != INVALID_FILE_ATTRIBUTES) // Существует такой?
		{
			if ((JSAttr&FILE_ATTRIBUTE_DIRECTORY)!=FILE_ATTRIBUTE_DIRECTORY)
			{
				if (!(Flags&FCOPY_NOSHOWMSGLINK))
				{
					Message(MSG_WARNING,1,MSG(MError),
					        MSG(MCopyCannotCreateJunctionToFile),
					        strDestFullName,MSG(MOk));
				}

				return 0;
			}

			if (TestFolder(strDestFullName) == TSTFLD_NOTEMPTY) // а пустой?
			{
				// не пустой, ну что же, тогда пробуем сделать dest\srcname
				AddEndSlash(strDestFullName);

				if (LinkType==RP_VOLMOUNT)
				{
					string strTmpName;
					strTmpName.Format(MSG(MCopyMountName),*SelName);
					strDestFullName += strTmpName;
					AddEndSlash(strDestFullName);
				}
				else
					strDestFullName += PtrSelName;

				JSAttr=apiGetFileAttributes(strDestFullName);

				if (JSAttr != INVALID_FILE_ATTRIBUTES) // И такой тоже есть???
				{
					if (TestFolder(strDestFullName) == TSTFLD_NOTEMPTY) // а пустой?
					{
						if (!(Flags&FCOPY_NOSHOWMSGLINK))
						{
							if (LinkType==RP_VOLMOUNT)
							{
								strMsgBuf.Format(MSG(MCopyMountVolFailed), SelName);
								strMsgBuf2.Format(MSG(MCopyMountVolFailed2), strDestFullName.CPtr());
								Message(MSG_WARNING,1,MSG(MError),
								        strMsgBuf,
								        strMsgBuf2,
								        MSG(MCopyFolderNotEmpty),
								        MSG(MOk));
							}
							else
								Message(MSG_WARNING,1,MSG(MError),
								        MSG(MCopyCannotCreateLink),strDestFullName,
								        MSG(MCopyFolderNotEmpty),MSG(MOk));
						}

						return 0; // однозначно в морг
					}
				}
				else // создаем.
				{
					if (apiCreateDirectory(strDestFullName,nullptr))
						TreeList::AddTreeName(strDestFullName);
					else
						CreatePath(strDestFullName);
				}

				if (apiGetFileAttributes(strDestFullName) == INVALID_FILE_ATTRIBUTES) // так, все очень даже плохо.
				{
					if (!(Flags&FCOPY_NOSHOWMSGLINK))
					{
						Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MError),
						        MSG(MCopyCannotCreateFolder),
						        strDestFullName,MSG(MOk));
					}

					return 0;
				}
			}
		}
		else
		{
			if (LinkType==RP_SYMLINK || LinkType==RP_SYMLINKFILE || LinkType==RP_SYMLINKDIR)
			{
				// в этом случае создается путь, но не сам каталог
				string strPath=strDestFullName;

				if (CutToSlash(strPath))
				{
					if (apiGetFileAttributes(strPath)==INVALID_FILE_ATTRIBUTES)
						CreatePath(strPath);
				}
			}
			else
			{
				bool CreateDir=true;

				if (LinkType==RP_EXACTCOPY)
				{
					// в этом случае создается или каталог, или пустой файл
					DWORD dwSrcAttr=apiGetFileAttributes(strSrcFullName);

					if (dwSrcAttr!=INVALID_FILE_ATTRIBUTES && !(dwSrcAttr&FILE_ATTRIBUTE_DIRECTORY))
						CreateDir=false;
				}

				if (CreateDir)
				{
					if (apiCreateDirectory(strDestFullName,nullptr))
						TreeList::AddTreeName(strDestFullName);
					else
						CreatePath(strDestFullName);
				}
				else
				{
					string strPath=strDestFullName;

					if (CutToSlash(strPath))
					{
						// создаём
						if (apiGetFileAttributes(strPath)==INVALID_FILE_ATTRIBUTES)
							CreatePath(strPath);

						File file;
						if(file.Open(strDestFullName, 0, 0, 0, CREATE_NEW, apiGetFileAttributes(strSrcFullName)))
						{
							file.Close();
						}
					}
				}

				if (apiGetFileAttributes(strDestFullName) == INVALID_FILE_ATTRIBUTES) // так. все очень даже плохо.
				{
					if (!(Flags&FCOPY_NOSHOWMSGLINK))
					{
						Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MError),
						        MSG(MCopyCannotCreateLink),strDestFullName,MSG(MOk));
					}

					return 0;
				}
			}
		}

		if (LinkType!=RP_VOLMOUNT)
		{
			if (CreateReparsePoint(strSrcFullName,strDestFullName,LinkType))
			{
				return 1;
			}
			else
			{
				if (!(Flags&FCOPY_NOSHOWMSGLINK))
				{
					Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MError),
					        MSG(MCopyCannotCreateLink),strDestFullName,MSG(MOk));
				}

				return 0;
			}
		}
		else
		{
			if (CreateVolumeMountPoint(strSrcFullName,strDestFullName))
			{
				return 1;
			}
			else
			{
				if (!(Flags&FCOPY_NOSHOWMSGLINK))
				{
					strMsgBuf.Format(MSG(MCopyMountVolFailed),SelName);
					strMsgBuf2.Format(MSG(MCopyMountVolFailed2),strDestFullName.CPtr());
					Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MError),strMsgBuf,strMsgBuf2,MSG(MOk));
				}

				return 0;
			}
		}
	}

	return 2;
}