Ejemplo n.º 1
0
bool OperCFThread::DeleteList( FS* fs, FSPath& _path, FSList& list )
{
	if ( Info()->Stopped() ) { return false; }

	FSPath path = _path;
	int cnt = path.Count();

	for ( FSNode* node = list.First(); node; node = node->next )
	{
		if ( node->extType ) { continue; }

		path.SetItemStr( cnt, node->Name() );

		if ( node->IsDir() && !node->st.IsLnk() )
		{
			if ( !DeleteDir( fs, path ) ) { return false; }

			if ( !RmDir( fs, path ) ) { return false; }

			continue;
		}

		if ( !DeleteFile( fs, path ) ) { return false; }
	}

	return true;
}
BOOL CWinHTTrackApp::RmDir(CString srcpath) {
  CWaitCursor wait;

  if (srcpath.GetLength()==0)
    return FALSE;
  CString path=srcpath;
  WIN32_FIND_DATA find;
  if (path.Right(1)!="\\")
    path+="\\";  
  HANDLE h = FindFirstFile(path+"*.*",&find);
  if (h != INVALID_HANDLE_VALUE) {
    do {
      if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM ))
      if (strcmp(find.cFileName,".."))
      if (strcmp(find.cFileName,"."))
        if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY )) {
          if (remove(path+find.cFileName)) {
            AfxMessageBox("Error deleting "+path+find.cFileName);
            return FALSE;
          }
        } else {
          if (!RmDir(path+find.cFileName))
            return FALSE;
        }
    } while(FindNextFile(h,&find));
    FindClose(h);
  }
  if (rmdir(srcpath)) {
    AfxMessageBox("Error deleting "+srcpath);
    return FALSE;
  }
  return TRUE;
}
Ejemplo n.º 3
0
bool wxCurlFTP::Delete(const wxString& szRemoteLoc /*= wxEmptyString*/)
{
	if(m_pCURL)
	{
		SetCurlHandleToDefaults(szRemoteLoc);

        wxString url(GetURL().c_str(), wxConvUTF8);
		m_szCurrFullPath = url.BeforeLast('/');
		m_szCurrFullPath += wxS("/");
		m_szCurrFilename = url.AfterLast('/');

		if(m_szCurrFilename.IsEmpty())
			return RmDir(szRemoteLoc);

		AppendPostQuote(wxS("DELE ") + m_szCurrFilename, true);

		SetCurlHandleQuoteOpts();
		SetOpt(CURLOPT_NOBODY, TRUE);

		if(Perform())
		{
			ResetAllQuoteLists();

			return ((m_iResponseCode > 199) && (m_iResponseCode < 300));
		}

		ResetAllQuoteLists();
	}

	return false;
}
Ejemplo n.º 4
0
void RmDir(const char *path)
{
	if(IsFile(path) || IsLnk(path))
	{
		remove(path);
		return;
	}
	char filePath[PATH_MAX];
	if(IsDir(path))
	{
		DIR *dir;
		struct dirent *ptr;
		dir = opendir(path);
		while(ptr = readdir(dir))
		{
			if(IsSpecial(ptr->d_name))
				continue;
			GetFilePath(path,ptr->d_name,filePath);
			if(IsDir(filePath))
			{
				RmDir(filePath);
				rmdir(filePath);
			}
			else if(IsFile(filePath) || IsLnk(filePath))
			{
				remove(filePath);
			}
		}
		closedir(dir);
	}
}
Ejemplo n.º 5
0
bool sprawl::filesystem::RmTree(sprawl::String const& path)
{
	if(!path::IsDirectory(path))
	{
		return Remove(path);
	}

	auto dirList = ListDir(path);

	for(auto& entry : dirList)
	{
		entry = path::Join(path, entry);
		if(path::IsDirectory(entry) && !path::IsLink(entry))
		{
			if(!RmTree(entry))
			{
				return false;
			}
		}
		else
		{
			if(!Remove(entry))
			{
				return false;
			}
		}
	}

	if(!RmDir(path))
	{
		return false;
	}

	return true;
}
Ejemplo n.º 6
0
bool sprawl::filesystem::RemoveDirs(sprawl::String const& path)
{
	char const* const start = path.c_str();
	char const* end = start + path.length() - 1;
	char const sep = path::Separator();
	char const altSep = path::AltSeparator();
	bool retcode = false;

	while (*end == sep || *end == altSep)
	{
		--end;
	}

	while(end > start)
	{
		if(!RmDir(sprawl::String(start, end - start + 1)))
		{
			return retcode;
		}
		retcode = true;
		//Backtrack to last separator
		while (*end != sep && *end != altSep)
		{
			--end;
		}
		//And beyond it
		while(*end == sep || *end == altSep)
		{
			--end;
		}
	}
	return true;
}
Ejemplo n.º 7
0
void RequestTests::Test_PdbImport()
{
	bool bExec = false;
    CMtClient client("127.0.0.1", 50);
    std::string sErrorMsg;
	int nServerRetCode = -1;
	std::string sServerResponse;
	std::ostringstream stCommand;
	std::wstring sPdbName;
	std::wstring sSymDir;
	std::wstring sOutFile;
	int nCreateDir = -1;

	sPdbName = Utils::GetTestDataFolder();
	sPdbName += L"CrashRpt.pdb";

	// Create symbol store dir
	sSymDir = Utils::GetTestDataFolder();
	sSymDir += L"sym";
	RmDir(sSymDir, false);
	nCreateDir = CreateDir(sSymDir);
	TEST_ASSERT_MSG(nCreateDir==0, "Error creating directory '%s'", strconv::w2a(sSymDir).c_str());

	sOutFile = sSymDir;
#ifdef _WIN32
	sOutFile += L"\\CrashRpt.pdb.txt";
#else
    sOutFile += L"/CrashRpt.pdb.txt";
#endif

	// Format command
	stCommand << "dumper --import-pdb \"" <<
		strconv::w2utf8(sPdbName) << "\" \"" <<
		strconv::w2utf8(sSymDir) << "\" \"" <<
		strconv::w2utf8(sOutFile) << "\"\n";

	// Execute daemon status command - assume success
    bExec = client.ExecuteRequest(stCommand.str().c_str(), nServerRetCode, sServerResponse, sErrorMsg);
	TEST_ASSERT_MSG(bExec, sErrorMsg.c_str());
	TEST_ASSERT_MSG(nServerRetCode==0, "Invalid ret code %d, msg = %s", nServerRetCode, sServerResponse.c_str());

	__TEST_CLEANUP__;

	// Delete sym directory
    RmDir(sSymDir, false);

}
Ejemplo n.º 8
0
bool CPdbCache::DeletePdbFile(std::wstring sPath)
{
    FixSlashesInFilePath(sPath);

    // First check if file is located inside of a search directory
    bool bMatch = false;
    std::map<std::wstring, _SearchDirInfo>::iterator it;
    for(it=m_aSearchDirs.begin(); it!=m_aSearchDirs.end(); it++)
    {
        _SearchDirInfo& info = it->second;
        int pos = sPath.find(info.m_sPath);
        if(pos==0)
        {
            // The file is located in this search path
            bMatch = true;
            break;
        }
    }
    if(!bMatch)
        return false; // File is not in PDB cache search path

    // Remove the file itself
    int nRes = RemoveFile(sPath);
    if(nRes!=0)
        return false; // Error deleting file

    std::wstring sDir;
    std::wstring sFile;
    std::wstring sBaseFileName;
    std::wstring sExtension;
    std::wstring sSubDirName;
    SplitFileName(sPath, sDir, sFile, sBaseFileName, sExtension);
    SplitFileName(sDir, sSubDirName, sFile, sBaseFileName, sExtension);

    // Remove the containing folder (if empty)
    RmDir(sDir, true);

    // Remove the outer containing folder (if empty)
    RmDir(sSubDirName, true);

    return true;
}
Ejemplo n.º 9
0
bool OperCFThread::CopyDir(FS *srcFs, FSPath &__srcPath, FSNode *srcNode, FS *destFs, FSPath &__destPath, bool move)
{
	if (Info()->Stopped()) return false;

	FSList list;
	
	int ret_error;
	
	while (true) {
		int ret = srcFs->ReadDir(&list, __srcPath, &ret_error, Info());
		if (ret == -2) return false;
		if (!ret) break;

		switch ( RedMessage( _LT("Can`t open directory:\n") , srcFs->Uri(__srcPath).GetUtf8(), bRetrySkipCancel, srcFs->StrError(ret_error).GetUtf8()) ) {
		case CMD_SKIP: return true;
		case CMD_RETRY: continue;
		default: return false;
		}
	}
	
	while (destFs->MkDir(__destPath, MkDirMode, &ret_error, Info()) && !destFs->IsEEXIST(ret_error)) {
		switch (RedMessage( _LT("Can't create the directory:\n"), destFs->Uri(__destPath).GetUtf8(), bRetrySkipCancel, destFs->StrError(ret_error).GetUtf8())) {
		case CMD_CANCEL: return false;
		case CMD_SKIP: return true;
		}
	}
		
	
	FSPath srcPath = __srcPath; int srcPos = srcPath.Count();
	FSPath destPath = __destPath; int destPos = destPath.Count();
	
		
	for (FSNode *node = list.First(); node; node = node->next) 
	{
		if (Info()->Stopped()) return false;
		
		srcPath.SetItemStr(srcPos, node->Name());
		destPath.SetItemStr(destPos, node->Name());
		
		if (!CopyNode(srcFs, srcPath, node, destFs, destPath, move)) return false; 
	}

	destFs->SetFileTime(destPath, srcNode->st.mtime, srcNode->st.mtime, 0, Info());

	return !move || RmDir(srcFs, __srcPath);
}
void CWinHTTrackApp::OnFileDelete()
{
  static char szFilter[256];
  strcpybuff(szFilter,"WinHTTrack Website Copier Project (*.whtt)|*.whtt||");
  CFileDialog* dial = new CFileDialog(true,"whtt",NULL,OFN_HIDEREADONLY,szFilter);
  if (dial->DoModal() == IDOK) {
    CString st=dial->GetPathName();
    if (fexist((char*) LPCTSTR(st))) {
      int pos=st.ReverseFind('.');
      CString dir=st.Left(pos)+"\\";
      char msg[1000];
      sprintf(msg,"%s\r\n%s",LANG_DELETECONF,dir);
      if (AfxMessageBox(msg,MB_OKCANCEL)==IDOK) {
        if (remove(st)) {
          AfxMessageBox("Error deleting "+st);
        } else {
          RmDir(dir);
        }
      }
    } else
      AfxMessageBox(LANG(LANG_G26 /*"File not found!","Fichier introuvable!"*/));
  }
  delete dial;
}
Ejemplo n.º 11
0
int OperCFThread::MoveDir( FS* srcFs, FSPath& __srcPath, FSNode* srcNode, FS* destFs, FSPath& __destPath )
{
	if ( Info()->Stopped() ) { return -1; }

	if ( srcFs != destFs ) { return 1; }

	FSPath srcPath = __srcPath;
	int srcPos = srcPath.Count();
	FSPath destPath = __destPath;
	int destPos = destPath.Count();

	if ( IsSameFile( srcFs, srcPath, &( srcNode->st ), destFs, destPath ) )
	{
		RedMessage( _LT( "Can't move directory to itself:\n" ), srcFs->Uri( __srcPath ).GetUtf8() );
		return -1;
	}

	FSStat st;
	int ret_error;

	if ( !destFs->Stat( destPath, &st, &ret_error, Info() ) )
	{
		if ( !st.IsDir() )
		{
			switch ( RedMessage( _LT( "Can't copy directory\n" ), srcFs->Uri( srcPath ).GetUtf8(), _LT( "to file" ), "\n", _LT( "Delete the file?" ), destFs->Uri( destPath ).GetUtf8(), bOkSkipCancel ) )
			{
				case CMD_CANCEL:
					return -1;

				case CMD_SKIP:
					return 0;
			}

			if ( !Unlink( destFs, destPath ) ) { return -1; }
		}
		else
		{

			FSList list;

			while ( true )
			{
				int ret = srcFs->ReadDir( &list, srcPath, &ret_error, Info() );

				if ( ret == -2 ) { return -1; }

				if ( !ret ) { break; }

				switch ( RedMessage( _LT( "Can`t open directory:\n" ), srcFs->Uri( __srcPath ).GetUtf8(), bRetrySkipCancel, srcFs->StrError( ret_error ).GetUtf8() ) )
				{
					case CMD_SKIP:
						return 0;

					case CMD_RETRY:
						continue;

					default:
						return -1;
				}
			}

			for ( FSNode* node = list.First(); node; node = node->next )
			{
				if ( Info()->Stopped() ) { return -1; }

				srcPath.SetItemStr( srcPos, node->Name() );
				destPath.SetItemStr( destPos, node->Name() );

				if ( !MoveFile( srcFs, srcPath, node, destFs, destPath ) ) { return -1; }

			}

			destFs->SetFileTime( destPath, srcNode->st.m_CreationTime, srcNode->st.m_LastWriteTime, srcNode->st.m_LastWriteTime, 0, Info() );

			return RmDir( srcFs, srcPath ) ? 0 : -1;
		}
	}

	if ( srcFs->Rename( srcPath, destPath, &ret_error, Info() ) )
	{
		if ( srcFs->IsEXDEV( ret_error ) ) { return 1; }

		return RedMessage( _LT( "Can't rename the directory:\n" ), srcFs->Uri( srcPath ).GetUtf8(), "\nto\n", destFs->Uri( destPath ).GetUtf8(),
		                   bSkipCancel, srcFs->StrError( ret_error ).GetUtf8() ) == CMD_SKIP ? 0 : -1;

	}

	return 0;
}
Ejemplo n.º 12
0
void RequestTests::Test_DumpCrashReport_assync()
{
	bool bExec = false;
    CMtClient client("127.0.0.1", 50);
    std::string sErrorMsg;
	int nServerRetCode = -1;
	std::string sServerResponse;
	std::string sCommand;
	std::wstring sFileName;
	std::wstring sTmpDir;
	std::wstring sOutFile;
	int nCreateDir = -1;
	std::vector<std::wstring> asCrashReports;
	CFileFinder FileFinder;
	CFindFileInfo ffi;
	bool bFind = false;
	std::wstring sTmpName;
	TiXmlDocument doc;
	std::string sCmdId;
	int pos1, pos2, pos3, pos4;

	sFileName = Utils::GetTestDataFolder();
	sFileName += L"crashReports\\WTLDemo\\1.4.0.0\\*.zip";

	// Get the list of crash reports in the directory
	bFind = FileFinder.FindFirstFile(sFileName, &ffi);
	while(bFind)
	{
		asCrashReports.push_back(ffi.m_sFileName);
		bFind = FileFinder.FindNextFile(&ffi);
	}
	// Ensure there are enough crash reports found
	TEST_ASSERT(asCrashReports.size()>=10);

	// Create temp out dir
	sTmpDir = Utils::GetTestDataFolder();
	sTmpDir += L"temp_dir1";
	RmDir(sTmpDir, false);
	nCreateDir = CreateDir(sTmpDir);
	TEST_ASSERT_MSG(nCreateDir==0, "Error creating directory '%s'", strconv::w2a(sTmpDir).c_str());

	size_t i;
	for(i=0; i<asCrashReports.size(); i++)
	{
		std::ostringstream stCommand;
		sFileName = asCrashReports[i];

		sOutFile = sTmpDir+L"\\result.xml";

		// Format command
		stCommand << "assync dumper --dump-crash-report \"" <<
			strconv::w2utf8(sFileName) << "\" \"" <<
			strconv::w2utf8(sOutFile) << "\"\n";
		sCommand = stCommand.str();

		// Execute daemon command - assume success
		bExec = client.ExecuteRequest(sCommand.c_str(), nServerRetCode, sServerResponse, sErrorMsg);
		TEST_ASSERT_MSG(bExec, sErrorMsg.c_str());
		TEST_ASSERT_MSG(nServerRetCode==0, "Invalid ret code %d, msg = %s", nServerRetCode, sServerResponse.c_str());

		// Get command id
		pos1 = sServerResponse.find('{');
		pos2 = sServerResponse.find('}', pos1+1);
		sCmdId = sServerResponse.substr(pos1+1, pos2-pos1-1);

		// Wait until command is finished
		for(;;)
		{
			std::string sRetMsg;

			std::ostringstream stCommand;
			stCommand << "daemon get-assync-info -erase-completed  " << sCmdId << "\n";
			sCommand = stCommand.str();

			bExec = client.ExecuteRequest(sCommand.c_str(), nServerRetCode, sServerResponse, sErrorMsg);
			TEST_ASSERT_MSG(bExec, sErrorMsg.c_str());
			TEST_ASSERT_MSG(nServerRetCode==0, "Invalid ret code %d, msg = %s", nServerRetCode, sServerResponse.c_str());

			if(sServerResponse.find("still executing")!=sServerResponse.npos)
			{
				Sleep(1000);
				continue;
			}

			// Get command id and return message
			pos1 = sServerResponse.find('{');
			pos2 = sServerResponse.find('}', pos1+1);
			sCmdId = sServerResponse.substr(pos1+1, pos2-pos1-1);

			pos3 = sServerResponse.find('{', pos2+1);
			pos4 = sServerResponse.find('}', pos3+1);
			sRetMsg = sServerResponse.substr(pos3+1, pos4-pos3-1);

			TEST_ASSERT(sRetMsg=="0 Success");
			break;
		}

		// Check that result is a valid XML file
		bool bLoad = doc.LoadFile(strconv::w2a(sOutFile).c_str());
		TEST_ASSERT(bLoad);

		// Get element
		TiXmlHandle hElem = doc.RootElement();
		TEST_ASSERT(hElem.ToElement()!=NULL);
		hElem = hElem.FirstChild("Summary");
		TEST_ASSERT(hElem.ToElement()!=NULL);

		// Remove file
		remove(strconv::w2a(sOutFile).c_str());
	}

	__TEST_CLEANUP__;

	// Delete temp directory
    RmDir(sTmpDir, false);

}
Ejemplo n.º 13
0
/*
 * Execute command.
 */
void
DoCommand(
	Client_t *cli)
{
	int rc;
	char *cmd_name;
	char *lasts;
	char *msg;

	rc = 0;
	SetErrno = 0;

	msg = cli->cmdbuf;
	/*
	 * Extract command name.
	 */
/* LINTED improper pointer/integer combination */
	cmd_name = strtok_r(msg, " ", &lasts);

	if (strcmp(cmd_name, SAMRFT_CMD_CONNECT) == 0) {
		SendReply(cli, "%s %d %d", SAMRFT_CMD_CONNECT, 0, 0);

	} else if (strcmp(cmd_name, SAMRFT_CMD_CONFIG) == 0) {
		char *hostname;
		int blksize;
		int tcpwindowsize;

		hostname = getString(&lasts);
		blksize = GetCfgBlksize();
		tcpwindowsize = GetCfgTcpWindowsize();

		SamStrdup(cli->hostname, hostname);
		rc = CreateCrew(cli, 1, blksize);

		SendReply(cli, "%s %d %d %d %d",
		    SAMRFT_CMD_CONFIG, rc, 1, blksize, tcpwindowsize);

	} else if (strcmp(cmd_name, SAMRFT_CMD_OPEN) == 0) {
		char *filename;
		int oflag;
		SamrftCreateAttr_t creat;

		filename = getString(&lasts);
		oflag = getInteger(&lasts);

		if (getInteger(&lasts)) {
			(void) memset((char *)&creat, 0,
			    sizeof (SamrftCreateAttr_t));
			creat.mode = getInteger(&lasts);
			creat.uid = getInteger(&lasts);
			creat.gid = getInteger(&lasts);
			rc = OpenFile(cli, filename, oflag, &creat);
		} else {
			rc = OpenFile(cli, filename, oflag, NULL);
		}

		SendReply(cli, "%s %d %d", SAMRFT_CMD_OPEN, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_DPORT) == 0) {
		struct sockaddr_in data;
		int seqnum;
		char *addr = (char *)&data.sin_addr;
		char *port = (char *)&data.sin_port;

		(void) memset((char *)&data, 0, sizeof (struct sockaddr_in));
		data.sin_family = AF_INET;

		seqnum = getInteger(&lasts);

		/*
		 * Addr.
		 */
		addr[0] = getInteger(&lasts);
		addr[1] = getInteger(&lasts);
		addr[2] = getInteger(&lasts);
		addr[3] = getInteger(&lasts);

		/*
		 * Port.
		 */
		port[0] = getInteger(&lasts);
		port[1] = getInteger(&lasts);

		rc = InitDataConnection(cli, "r", seqnum,
		    data.sin_family, (struct sockaddr *)&data);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_DPORT, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_DPORT6) == 0) {
		struct sockaddr_in6 data;
		struct sockaddr_in *data4 = (struct sockaddr_in *)&data;
		int i;
		int seqnum;
		char *addr;
		char *port;

		(void) memset((char *)&data, 0, sizeof (struct sockaddr_in6));

		seqnum = getInteger(&lasts);

		/*
		 * Address family.
		 */
		data.sin6_family = getInteger(&lasts);
		if (data.sin6_family == AF_INET6) {
			addr = (char *)&data.sin6_addr;
			port = (char *)&data.sin6_port;
		} else {
			addr = (char *)&data4->sin_addr;
			port = (char *)&data4->sin_port;
		}

		/*
		 * Addr.
		 */
		for (i = 0; i < 16; i++) {
			addr[i] = getInteger(&lasts);
		}

		/*
		 * Port.
		 */
		port[0] = getInteger(&lasts);
		port[1] = getInteger(&lasts);

		rc = InitDataConnection(cli, "r", seqnum,
		    data.sin6_family, (struct sockaddr *)&data);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_DPORT6, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_STOR) == 0) {
		fsize_t nbytes;

		nbytes = getLongLong(&lasts);
		rc = ReceiveData(cli, nbytes);

	} else if (strcmp(cmd_name, SAMRFT_CMD_SEND) == 0) {
		size_t nbytes;

		nbytes = getInteger(&lasts);

		rc = ReceiveData(cli, nbytes);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_SEND, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_RECV) == 0) {
		size_t nbytes;

		nbytes = getInteger(&lasts);

		/*
		 * Process receive command from client.  Send data from local
		 * file over data sockets to the client process.
		 */
		rc = SendData(cli, nbytes);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_RECV, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_SEEK) == 0) {
		off64_t setpos;
		int whence;
		off64_t offset;

		setpos = getLongLong(&lasts);
		whence = getInteger(&lasts);

		rc = SeekFile(cli, setpos, whence, &offset);
		SendReply(cli, "%s %d %d %lld", SAMRFT_CMD_SEEK,
		    rc, errno, offset);

	} else if (strcmp(cmd_name, SAMRFT_CMD_FLOCK) == 0) {
		int type;

		type = getInteger(&lasts);

		rc = FlockFile(cli, type);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_FLOCK, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_ARCHIVEOP) == 0) {
		char *path;
		char *ops;

		path = getString(&lasts);
		ops = getString(&lasts);

		rc = sam_archive(path, ops);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_ARCHIVEOP, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_CLOSE) == 0) {

		rc = CloseFile(cli);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_CLOSE, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_UNLINK) == 0) {
		char *name;

		name = getString(&lasts);

		rc = UnlinkFile(cli, name);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_UNLINK, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_DISCONN) == 0) {

		Trace(TR_DEBUG, "RFT disconnect, no reply: '%s'", cli->cmdbuf);
		CleanupCrew(cli);
		cli->disconnect = 1;

		/*
		 * No reply.
		 */

	} else if (strcmp(cmd_name, SAMRFT_CMD_ISMOUNTED) == 0) {
		int mounted;
		char *mount_point;

		mount_point = getString(&lasts);

		mounted = IsMounted(cli, mount_point);
		SendReply(cli, "%s %d", SAMRFT_CMD_ISMOUNTED, mounted);

	} else if (strcmp(cmd_name, SAMRFT_CMD_STAT) == 0) {
		struct stat64 buf;
		char *filename;

		filename = getString(&lasts);

		(void) memset(&buf, 0, sizeof (buf));
		rc = stat64(filename, &buf);
		SendReply(cli, "%s %d %d %d %d %d %lld",
		    SAMRFT_CMD_STAT, rc, errno,
		    buf.st_mode, buf.st_uid, buf.st_gid, buf.st_size);

	} else if (strcmp(cmd_name, SAMRFT_CMD_STATVFS) == 0) {
		struct statvfs64 buf;
		char *mount_point;
		int offlineFiles;
		fsize_t offlineFileSize;

		mount_point = getString(&lasts);
		offlineFiles = getInteger(&lasts);

		(void) memset(&buf, 0, sizeof (buf));
		rc = statvfs64(mount_point, &buf);

		if (rc == 0 && (strcmp(buf.f_basetype, "samfs") == 0) &&
		    offlineFiles == B_TRUE) {
			offlineFileSize = DiskVolsOfflineFiles(mount_point);
			/*
			 * Adjust capacity to include size of offline files.
			 */
			buf.f_blocks += offlineFileSize / buf.f_frsize;
		}

		SendReply(cli, "%s %d %d %lld %lld %ld %s",
		    SAMRFT_CMD_STATVFS, rc, errno,
		    buf.f_bfree, buf.f_blocks, buf.f_frsize, buf.f_basetype);

	} else if (strcmp(cmd_name, SAMRFT_CMD_SPACEUSED) == 0) {
		char *path;
		fsize_t spaceUsed;

		path = getString(&lasts);

		spaceUsed = DiskVolsAccumSpaceUsed(path);

		SendReply(cli, "%s %d %d %lld",
		    SAMRFT_CMD_SPACEUSED, rc, errno, spaceUsed);

	} else if (strcmp(cmd_name, SAMRFT_CMD_MKDIR) == 0) {
		char *dirname;
		int mode, uid, gid;

		dirname = getString(&lasts);
		mode = getInteger(&lasts);
		uid = getInteger(&lasts);
		gid = getInteger(&lasts);

		rc = MkDir(cli, dirname, mode, uid, gid);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_MKDIR, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_OPENDIR) == 0) {
		char *dirname;
		int dirp;

		dirname = getString(&lasts);

		rc = OpenDir(cli, dirname, &dirp);
		SendReply(cli, "%s %d %d %d", SAMRFT_CMD_OPENDIR,
		    rc, errno, dirp);

	} else if (strcmp(cmd_name, SAMRFT_CMD_READDIR) == 0) {
		int dirp;
		SamrftReaddirInfo_t dir_info;

		dirp = getInteger(&lasts);

		rc = ReadDir(cli, dirp, &dir_info);
		if (rc == 0) {
			SendReply(cli, "%s %d %d %s %d", SAMRFT_CMD_READDIR,
			    rc, errno, dir_info.name, dir_info.isdir);
		} else {
			SendReply(cli, "%s %d %d", SAMRFT_CMD_READDIR,
			    rc, errno);
		}

	} else if (strcmp(cmd_name, SAMRFT_CMD_CLOSEDIR) == 0) {
		int dirp;

		dirp = getInteger(&lasts);

		CloseDir(cli, dirp);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_CLOSEDIR, 0, 0);

	} else if (strcmp(cmd_name, SAMRFT_CMD_RMDIR) == 0) {
		char *dirname;

		dirname = getString(&lasts);

		rc = RmDir(cli, dirname);
		SendReply(cli, "%s %d %d", SAMRFT_CMD_CLOSEDIR, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_LOADVOL) == 0) {
		struct sam_rminfo rb;
		int oflag;

		/*
		 * Create sam_rminfo structure used to create
		 * a removable-media file.
		 */
		(void) memset(&rb, 0, sizeof (rb));

		rb.flags = getInteger(&lasts);

		(void) strncpy(rb.file_id,  getString(&lasts),
		    sizeof (rb.file_id));
		(void) strncpy(rb.owner_id, getString(&lasts),
		    sizeof (rb.owner_id));
		(void) strncpy(rb.group_id, getString(&lasts),
		    sizeof (rb.group_id));

		rb.n_vsns = 1;
		(void) strncpy(rb.media, getString(&lasts), sizeof (rb.media));
		(void) strncpy(rb.section[0].vsn, getString(&lasts),
		    sizeof (rb.section[0].vsn));

		oflag = getInteger(&lasts);

		rc = LoadVol(cli, &rb, oflag);

		SendReply(cli, "%s %d %d", SAMRFT_CMD_LOADVOL, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_GETVOLINFO) == 0) {
		struct sam_rminfo getrm;
		int eq;

		rc = GetVolInfo(cli, &getrm, &eq);

		SendReply(cli, "%s %d %d %d %lld %d", SAMRFT_CMD_GETVOLINFO,
		    rc, errno, getrm.block_size, getrm.position, eq);

	} else if (strcmp(cmd_name, SAMRFT_CMD_SEEKVOL) == 0) {
		int block;

		block = getInteger(&lasts);

		rc = SeekVol(cli, block);

		SendReply(cli, "%s %d %d", SAMRFT_CMD_SEEKVOL, rc, errno);

	} else if (strcmp(cmd_name, SAMRFT_CMD_UNLOADVOL) == 0) {
		struct sam_ioctl_rmunload unload;

		/*
		 * Create sam_rmunload structure used to unload
		 * a removable-media file.
		 */
		(void) memset(&unload, 0, sizeof (unload));

		unload.flags = getInteger(&lasts);

		rc = UnloadVol(cli, &unload);

		SendReply(cli, "%s %d %d %lld", SAMRFT_CMD_UNLOADVOL,
		    rc, errno, unload.position);
	} else {
		Trace(TR_ERR, "Unknown RFT command: %s", cmd_name);
	}
}
Ejemplo n.º 14
0
void __fastcall TMainCaptureForm::Start(TCaptureWorkerForm *localCaptureWorkerForm, UnicodeString saveRoot, queue<BITMAP*> &bmpQueue, HANDLE hMutex, lsl_outlet outlet, double requestedFrameRate)
{

		localCaptureWorkerForm->VideoGrabber->AnalogVideoStandard = localCaptureWorkerForm->VideoGrabber->AnalogVideoStandardIndex ("NTSC M");


		localCaptureWorkerForm->VideoGrabber->RecordingInNativeFormat = false;

		localCaptureWorkerForm->VideoGrabber->FrameRate = edtRequestedFrameRate->Text.ToDouble();

		if(cbRecord->Checked == true) {
		  //	localCaptureWorkerForm->VideoGrabber->VideoProcessing_FlipVertical = true;//HACK FOR POINT GREY BUG, RECORD ONLY, flipVertCheckbox->Checked;


			localCaptureWorkerForm->SetQueue(bmpQueue, hMutex, outlet, requestedFrameRate);

			//save to specified filename
			int n=0;
			UnicodeString outputFileName;
			while(true) {
				if(cbCompress->Checked) {
					outputFileName =  saveRoot /*edOutput0->Text*/+ IntToStr(n)+".asf";
				} else {
					outputFileName =  saveRoot /*edOutput0->Text*/+ IntToStr(n)+".avi";
				}

				if(!FileExists(outputFileName)) break;
				++n;
			}
			MkDir(outputFileName);
			if(DirectoryExists(outputFileName)) RmDir(outputFileName);
			else {
				Application->MessageBoxA(L"Invalid path for writing movie.", L"Error", MB_OK);
				return;
			}

			localCaptureWorkerForm->VideoGrabber->RecordingFileName= outputFileName;

			//record audio?
			localCaptureWorkerForm->VideoGrabber->AudioRecording = cbRecordAudio->Checked;

			//turn off some unused features
			localCaptureWorkerForm->VideoGrabber->FrameGrabber = TFrameGrabber (0);

			//save as compressed asf
			localCaptureWorkerForm->VideoGrabber->VideoCompressor = cbVideoCodecs->ItemIndex;

			if(cbCompress->Checked) {
				localCaptureWorkerForm->VideoGrabber->CompressionMode = cm_CompressOnTheFly;
				localCaptureWorkerForm->VideoGrabber->RecordingMethod = rm_ASF;
			} else {

				localCaptureWorkerForm->VideoGrabber->CompressionMode = cm_NoCompression;
				localCaptureWorkerForm->VideoGrabber->RecordingMethod = rm_AVI;
			}


			localCaptureWorkerForm->VideoGrabber->HoldRecording = false;

			localCaptureWorkerForm->VideoGrabber->StartRecording();

		} else {
			localCaptureWorkerForm->VideoGrabber->VideoProcessing_FlipVertical = false;//HACK FOR POINT GREY BUG, RECORD ONLY, flipVertCheckbox->Checked;

			localCaptureWorkerForm->SetQueue(bmpQueue, hMutex, outlet, requestedFrameRate);

			localCaptureWorkerForm->VideoGrabber->StartPreview();

		}

}