Example #1
0
nsresult
nsDownloadScanner::Scan::Start()
{
  mStartTime = PR_Now();

  mThread = (HANDLE)_beginthreadex(NULL, 0, ScannerThreadFunction,
      this, CREATE_SUSPENDED, NULL);
  if (!mThread)
    return NS_ERROR_OUT_OF_MEMORY;

  nsresult rv = NS_OK;

  // Default is to try to clean downloads
  mIsReadOnlyRequest = PR_FALSE;

  nsCOMPtr<nsIPrefBranch> pref =
    do_GetService(NS_PREFSERVICE_CONTRACTID);
  if (pref)
    rv = pref->GetBoolPref(PREF_BDA_DONTCLEAN, &mIsReadOnlyRequest);

  // Get the path to the file on disk
  nsCOMPtr<nsILocalFile> file;
  rv = mDownload->GetTargetFile(getter_AddRefs(file));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = file->GetPath(mPath);
  NS_ENSURE_SUCCESS(rv, rv);

  // Grab the app name
  nsCOMPtr<nsIXULAppInfo> appinfo =
    do_GetService(XULAPPINFO_SERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString name;
  rv = appinfo->GetName(name);
  NS_ENSURE_SUCCESS(rv, rv);
  CopyUTF8toUTF16(name, mName);

  // Get the origin
  nsCOMPtr<nsIURI> uri;
  rv = mDownload->GetSource(getter_AddRefs(uri));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString origin;
  rv = uri->GetSpec(origin);
  NS_ENSURE_SUCCESS(rv, rv);

  CopyUTF8toUTF16(origin, mOrigin);

  // We count https/ftp/http as an http download
  PRBool isHttp(PR_FALSE), isFtp(PR_FALSE), isHttps(PR_FALSE);
  nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(uri);
  if (!innerURI) innerURI = uri;
  (void)innerURI->SchemeIs("http", &isHttp);
  (void)innerURI->SchemeIs("ftp", &isFtp);
  (void)innerURI->SchemeIs("https", &isHttps);
  mIsHttpDownload = isHttp || isFtp || isHttps;

  // IAttachementExecute prohibits src data: schemes by default but we
  // support them. Mark the download if it's a data scheme, so we
  // can skip off supplying the src to IAttachementExecute when we scan
  // the resulting file.
  (void)innerURI->SchemeIs("data", &mSkipSource);

  // ResumeThread returns the previous suspend count
  if (1 != ::ResumeThread(mThread)) {
    CloseHandle(mThread);
    return NS_ERROR_UNEXPECTED;
  }
  return NS_OK;
}
Example #2
0
bool CIwGameFile::Open(const char* path, const char* mode, bool blocking)
{
	FileAvailable = false;
	InMemory = false;

	// make sure user cannot open the file twice
	if (File != NULL)
	{
		Error = ErrorAlreadyOpen;
		return false;
	}

	// Get the path
	if (path != NULL)
		Filename.setString(path);
	else
		path = Filename.c_str();

	// Check we actually have a path
	if (path == NULL)
	{
		Error = ErrorInvalidPath;
		return false;
	}

	// Check to see if the file is located on the web
	if (isHttp(Filename.c_str(), Filename.GetLength()))
	{
		Download();

		if (blocking)
		{
			while (!FileAvailable)
			{
				IW_GAME_HTTP_MANAGER->Update();
				s3eDeviceYield(0);
			}
			if (Error != ErrorNone)
				return false;
		}

		return true;
	}
	else
	{
		if (mode == NULL)
		{
			Error = ErrorEmptyMode;
			return false;
		}
	}

	// Open the file
	File = s3eFileOpen(Filename.c_str(), mode);
	if (File == NULL)
	{
#if defined(_DEBUG)
		s3eFileGetError();
		CIwGameError::LogError("Error: CIwGameFile::Open(): ", s3eFileGetErrorString());
#endif	// _DEBUG
		Error = ErrorOpenFailed;
		return false;
	}

	FileAvailable = true;

	return true;
}