public static function execute($params)
 {
     $completed = false;
     // Set startBytes
     if (!isset($params['startBytes'])) {
         $params['startBytes'] = 0;
     }
     // Set endBytes
     if (!isset($params['endBytes'])) {
         $params['endBytes'] = ServMaskDropboxClient::CHUNK_SIZE;
     }
     // Set retry
     if (!isset($params['retry'])) {
         $params['retry'] = 0;
     }
     // Set Dropbox client
     $dropbox = new ServMaskDropboxClient(get_option('ai1wmde_dropbox_token'), get_option('ai1wmde_dropbox_ssl', true));
     // Get archive file
     $archive = fopen(ai1wm_archive_path($params), 'ab');
     try {
         // Increase number of retries
         $params['retry'] += 1;
         // Download file chunk
         $dropbox->getFile($params['filePath'], $archive, $params);
     } catch (Exception $e) {
         // Retry 3 times
         if ($params['retry'] <= 3) {
             return $params;
         }
         throw $e;
     }
     // Reset retry counter
     $params['retry'] = 0;
     // Close the archive file
     fclose($archive);
     // Calculate percent
     $percent = (int) ($params['startBytes'] / $params['totalBytes'] * 100);
     // Set progress
     Ai1wm_Status::progress($percent);
     // Next file chunk
     if (empty($params['totalBytes'])) {
         throw new Ai1wm_Import_Exception('Unable to import the archive! Please check file size parameter. ');
     } else {
         if ($params['totalBytes'] == $params['startBytes']) {
             $completed = true;
         }
     }
     // Set completed flag
     $params['completed'] = $completed;
     return $params;
 }
	public static function execute( $params ) {

		$completed = false;

		// File ID
		if ( ! isset( $params['fileId'] ) ) {
			throw new Ai1wm_Import_Exception(
				__( 'Google Drive File ID is not specified. ', AI1WMGE_PLUGIN_NAME )
			);
		}

		// Set startBytes
		if ( ! isset( $params['startBytes'] ) ) {
			$params['startBytes'] = 0;
		}

		// Set endBytes
		if ( ! isset( $params['endBytes'] ) ) {
			$params['endBytes'] = ServMaskGdriveClient::CHUNK_SIZE;
		}

		// Set retry
		if ( ! isset( $params['retry'] ) ) {
			$params['retry'] = 0;
		}

		// Set Google Drive client
		$gdrive = new ServMaskGdriveClient(
			get_option( 'ai1wmge_gdrive_token' ),
			get_option( 'ai1wmge_gdrive_ssl', true )
		);

		// Get archive file
		$archive = fopen( ai1wm_archive_path( $params ), 'ab' );

		try {
			// Increase number of retries
			$params['retry'] += 1;

			// Download file chunk
			$gdrive->getFile( $params['fileId'], $archive, $params );
		} catch ( Exception $e ) {
			// Retry 3 times
			if ( $params['retry'] <= 3 ) {
				return $params;
			}

			throw $e;
		}

		// Reset retry counter
		$params['retry'] = 0;

		// Close the archive file
		fclose( $archive );

		// Calculate percent
		$percent = (int) ( ( $params['startBytes'] / $params['totalBytes'] ) * 100 );

		// Set progress
		Ai1wm_Status::progress( $percent );

		// Next file chunk
		if ( empty( $params['totalBytes'] ) ) {
			throw new Ai1wm_Import_Exception( 'Unable to import the archive! Please check file size parameter. ');
		} else if ( $params['totalBytes'] == $params['startBytes'] ) {
			$completed = true;
		}

		// Set completed flag
		$params['completed'] = $completed;

		return $params;
	}