private IEnumerator IE_LoadScene(Function onStart, ProgressFunction onProgress, Function onFinish)
        {
            yield return(null);

            onStart();
            SceneController scenecontroller = UnityEngine.Object.FindObjectOfType <SceneController>();

            if (scenecontroller != null)
            {
                ProgressFunction targetSceneLoading         = (prog) => onProgress(0.5f + prog / 2);
                Function         targetSceneFinishedLoading = null;
                targetSceneFinishedLoading = () =>
                {
                    scenecontroller.OnSceneLoadingProgress -= targetSceneLoading;
                    scenecontroller.OnSceneLoadingFinished -= targetSceneFinishedLoading;
                    onFinish();
                    scenecontroller.StartScene();
                };

                _baseGameController.InjectMonoBehaviourController(scenecontroller);
                scenecontroller.OnSceneLoadingProgress += targetSceneLoading;
                scenecontroller.OnSceneLoadingFinished += targetSceneFinishedLoading;
                scenecontroller.Init();
            }
        }
示例#2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <exception cref="System.InvalidOperationException">This is thrown
 /// if <see cref="Curl"/> hasn't bee properly initialized.</exception>
 /// <exception cref="System.NullReferenceException">This is thrown if
 /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
 public Easy()
 {
     Curl.EnsureCurl();
     m_pCURL = External.curl_easy_init();
     EnsureHandle();
     External.curl_easy_setopt_int(m_pCURL, CURLoption.CURLOPT_NOPROGRESS,
                                   1);
     m_pMyStrings     = External.curl_shim_alloc_strings();
     m_pfWrite        = null;
     m_privateData    = null;
     m_writeData      = null;
     m_pfRead         = null;
     m_readData       = null;
     m_pfProgress     = null;
     m_progressData   = null;
     m_pfDebug        = null;
     m_debugData      = null;
     m_pfHeader       = null;
     m_headerData     = null;
     m_pfSSLContext   = null;
     m_sslContextData = null;
     m_pfIoctl        = null;
     m_ioctlData      = null;
     InstallDelegates();
 }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgressDialog"/> class.
        /// </summary>
        public ProgressDialog(ProgressFunction progressFunction, bool supportsCancellation)
        {
            SupportsCancellation = supportsCancellation;
            _progressFunction    = progressFunction;

            InitializeComponent();
            _baseSize = Size;
            SetCancellationControls();
        }
示例#4
0
        public void Download(string path, ProgressFunction callback)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException("Cannot be null or empty", "path");
            }

            GetTrack(device.Handle, trackStruct.item_id, path, callback, IntPtr.Zero);
        }
        public StreamProgress(Stream watchStream, ProgressFunction Callback)
        {
            if (watchStream == null) throw new ArgumentException("watchStream");
            //if (Callback == null) throw new ArgumentException("Callback");

            useProgressFunction = Callback;
            _WatchStream=watchStream;
            WatcherThread = new Thread(ThreadFunction);
            WatcherThread.Start();
        }
        public StreamProgress(Stream watchStream, ProgressBar Target)
        {
            if(watchStream==null) throw new ArgumentNullException("watchStream");
            if (Target == null) throw new ArgumentNullException("Target");

            useProgressFunction = defaultProgress;
            _WatchStream = watchStream;
            setProgress = Target;
            WatcherThread = new Thread(ThreadFunction);

            WatcherThread.Start();
        }
示例#7
0
 public void ActivateProgress(ProgressFunction function)
 {
     foreach (var p in list)
     {
         if (p == function)
         {
             p.isOn          = true;
             currentFunction = p;
             //Focus関連
             ApplyFocus();
         }
     }
 }
示例#8
0
        public List <Track> GetAllTracks(ProgressFunction callback)
        {
            IntPtr ptr = Track.GetTrackListing(Handle, callback, IntPtr.Zero);

            List <Track> tracks = new List <Track>();

            while (ptr != IntPtr.Zero)
            {
                TrackStruct track = (TrackStruct)Marshal.PtrToStructure(ptr, typeof(TrackStruct));
                Track.DestroyTrack(ptr);
                tracks.Add(new Track(track, this));
                ptr = track.next;
            }

            return(tracks);
        }
示例#9
0
        public List <Track> GetAllTracks(ProgressFunction callback)
        {
            IntPtr ptr = Track.GetTrackListing(Handle, callback, IntPtr.Zero);

            List <Track> tracks = new List <Track>();

            while (ptr != IntPtr.Zero)
            {
                // Destroy the struct after we use it to avoid potential referencing of freed memory.
                TrackStruct track = (TrackStruct)Marshal.PtrToStructure(ptr, typeof(TrackStruct));
                tracks.Add(new Track(track, this));
                Track.DestroyTrack(ptr);
                ptr = track.next;
            }

            return(tracks);
        }
示例#10
0
    // Use this for initialization
    protected void AwakeLoopAction(ActionEnum.Loop Kind,
                                   double maxValue = 60, double plusValue = 1)
    {
        StartBASE();
        text = GetComponentInChildren <Text>();
        if (GetComponentInChildren <Slider>() != null)
        {
            slider = GetComponentInChildren <Slider>();
        }

        this.kind = Kind;
        MaxValue  = maxValue;
        PlusValue = plusValue;

        popUp   = main.ActionPopUpPre.StartPopUp(gameObject, main.windowShowCanvas);
        need    = gameObject.AddComponent <NeedFunciton>();
        release = gameObject.AddComponent <ReleaseFunction>();
        release.StartFunction(gameObject, x => Sync(ref main.SR.released_loop[(int)kind], x), x => Sync(ref main.SR.completed_loop[(int)kind], x), x => Requires());
        progress = gameObject.AddComponent <ProgressFunction>();
        progress.StartProgress(gameObject, Need, slider, x => Sync(ref main.SR.paid_loop[(int)kind], x), x => Sync(ref main.SR.currentValue_loop[(int)kind], x));
    }
示例#11
0
        public void UploadTrack(string path, Track track, Folder folder, ProgressFunction callback)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            if (track == null)
            {
                throw new ArgumentNullException("track");
            }

            folder = folder ?? MusicFolder;
            if (folder != null)
            {
                track.trackStruct.parent_id = folder.FolderId;
            }

            // We send the trackstruct by ref so that when the file_id gets filled in, our copy is updated
            Track.SendTrack(Handle, path, ref track.trackStruct, callback, IntPtr.Zero);
            // LibMtp.GetStorage (Handle, 0);
        }
示例#12
0
        private void SetupSceneLoading()
        {
            Function start = () =>
            {
                _model.SetType(SceneLoadingType.Scene, 0);
                _view.Activate();
            };
            ProgressFunction progress = (prog) => _model.SetProgress(prog);
            Function         finish   = null;

            finish = () =>
            {
                OnSceneLoadingStart    -= start;
                OnSceneLoadingProgress -= progress;
                OnSceneLoadingFinished -= finish;
                _view.Deactivate();
            };

            OnSceneLoadingStart    += start;
            OnSceneLoadingProgress += progress;
            OnSceneLoadingFinished += finish;
        }
示例#13
0
 private Easy(Easy from)
 {
     m_pCURL = External.curl_easy_duphandle(from.m_pCURL);
     EnsureHandle();
     m_pMyStrings     = External.curl_shim_alloc_strings();
     m_pfWrite        = null;
     m_privateData    = null;
     m_writeData      = null;
     m_pfRead         = null;
     m_readData       = null;
     m_pfProgress     = null;
     m_progressData   = null;
     m_pfDebug        = null;
     m_debugData      = null;
     m_pfHeader       = null;
     m_headerData     = null;
     m_pfSSLContext   = null;
     m_sslContextData = null;
     m_pfIoctl        = null;
     m_ioctlData      = null;
     InstallDelegates();
 }
示例#14
0
 internal static void GetTrack(MtpDeviceHandle handle, uint trackId, string destPath, ProgressFunction callback, IntPtr data)
 {
     if (LIBMTP_Get_Track_To_File(handle, trackId, destPath, callback, data) != 0)
     {
         LibMtpException.CheckErrorStack(handle);
         throw new LibMtpException(ErrorCode.General, "Could not download track from the device");
     }
 }
示例#15
0
        /// <summary>
        /// Set options for this object. See the <c>EasyGet</c> sample for
        /// basic usage.
        /// </summary>
        /// <param name="option">This should be a valid <see cref="CURLoption"/>.</param>
        /// <param name="parameter">This should be a parameter of a varying
        /// type based on the value of the <c>option</c> parameter.</param>
        /// <exception cref="System.NullReferenceException">This is thrown if
        /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
        /// <returns>A <see cref="CURLcode"/>, typically obtained from
        /// <c>cURL</c> internally, but sometimes a
        /// <see cref="CURLcode.CURLE_BAD_FUNCTION_ARGUMENT"/>
        /// will be returned if the type of value of <c>parameter</c> is invalid.
        /// </returns>
        public CURLcode SetOpt(CURLoption option, Object parameter)
        {
            EnsureHandle();
            CURLcode retCode = CURLcode.CURLE_OK;

            // numeric cases
            if ((int)option < CURLOPTTYPE_OBJECTPOINT)
            {
                int i = 0;
                if (option == CURLoption.CURLOPT_DNS_USE_GLOBAL_CACHE ||
                    option == CURLoption.CURLOPT_SOURCE_PORT)
                {
                    return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                }
                else if (option == CURLoption.CURLOPT_TIMEVALUE)
                {
                    // unboxing may throw class cast exception
                    DateTime d = (DateTime)parameter;
                    DateTime startTime = new DateTime(1970, 1, 1);
                    TimeSpan currTime = new TimeSpan(DateTime.Now.Ticks -
                        startTime.Ticks);
                    i = Convert.ToInt32(currTime.TotalSeconds);
                }
                else
                    i = Convert.ToInt32(parameter);
                retCode = External.curl_easy_setopt(m_pCURL,
                    option, (IntPtr)i);
            }

            // object cases: the majority
            else if ((int)option < CURLOPTTYPE_FUNCTIONPOINT)
            {
                switch(option)
                {
                    // various data items
                    case CURLoption.CURLOPT_PRIVATE:
                        m_privateData = parameter; break;
                    case CURLoption.CURLOPT_WRITEDATA:
                        m_writeData = parameter; break;
                    case CURLoption.CURLOPT_READDATA:
                        m_readData = parameter; break;
                    case CURLoption.CURLOPT_PROGRESSDATA:
                        m_progressData = parameter; break;
                    case CURLoption.CURLOPT_DEBUGDATA:
                        m_debugData = parameter; break;
                    case CURLoption.CURLOPT_HEADERDATA:
                        m_headerData = parameter; break;
                    case CURLoption.CURLOPT_SSL_CTX_DATA:
                        m_sslContextData = parameter; break;
                    case CURLoption.CURLOPT_IOCTLDATA:
                        m_ioctlData = parameter; break;

                    // items that can't be set externally or
                    // obsolete items
                    case CURLoption.CURLOPT_ERRORBUFFER:
                    case CURLoption.CURLOPT_STDERR:
                    case CURLoption.CURLOPT_SOURCE_HOST:
                    case CURLoption.CURLOPT_SOURCE_PATH:
                    case CURLoption.CURLOPT_PASV_HOST:
                        return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;

                    // singular case for share
                    case CURLoption.CURLOPT_SHARE:
                    {
                        Share share = parameter as Share;
                        if (share == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        retCode = External.curl_easy_setopt(m_pCURL,
                            option, share.GetHandle());
                        break;
                    }

                    // multipart HTTP post
                    case CURLoption.CURLOPT_HTTPPOST:
                    {
                        MultiPartForm mf = parameter as MultiPartForm;
                        if (mf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        retCode = External.curl_easy_setopt(m_pCURL,
                            option, mf.GetHandle());
                        break;
                    }

                    // items curl wants as a curl_slist
                    case CURLoption.CURLOPT_HTTPHEADER:
                    case CURLoption.CURLOPT_PREQUOTE:
                    case CURLoption.CURLOPT_QUOTE:
                    case CURLoption.CURLOPT_POSTQUOTE:
                    case CURLoption.CURLOPT_SOURCE_QUOTE:
                    case CURLoption.CURLOPT_TELNETOPTIONS:
                    case CURLoption.CURLOPT_HTTP200ALIASES:
                    {
                        Slist slist = parameter as Slist;
                        if (slist == null) {
                            retCode = External.curl_easy_setopt(m_pCURL,
                                option, IntPtr.Zero);
                        }
                        else {
                            retCode = External.curl_easy_setopt(m_pCURL,
                                option, slist.GetHandle());
                        }
                        break;
                    }

                    // string items
                    default:
                    {
                        string s = parameter as string;
                        if (s == null) {
                            retCode = External.curl_easy_setopt(m_pCURL,
                                option, IntPtr.Zero);
                        }
                        else {
                            IntPtr pCurlStr = External.curl_shim_add_string(
                                m_pMyStrings, s);
                            if (pCurlStr != IntPtr.Zero)
                                retCode = External.curl_easy_setopt(m_pCURL,
                                    option, pCurlStr);
                        }
                        break;
                    }
                }                        
            }

            // FUNCTIONPOINT args, for delegates
            else if ((int)option < CURLOPTTYPE_OFF_T)
            {
                switch(option)
                {
                    case CURLoption.CURLOPT_WRITEFUNCTION:
                    {
                        WriteFunction wf = parameter as WriteFunction;
                        if (wf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfWrite = wf;
                        break;
                    }

                    case CURLoption.CURLOPT_READFUNCTION:
                    {
                        ReadFunction rf = parameter as ReadFunction;
                        if (rf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfRead = rf;
                        break;
                    }

                    case CURLoption.CURLOPT_PROGRESSFUNCTION:
                    {
                        ProgressFunction pf = parameter as ProgressFunction;
                        if (pf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfProgress = pf;
                        break;
                    }

                    case CURLoption.CURLOPT_DEBUGFUNCTION:
                    {
                        DebugFunction pd = parameter as DebugFunction;
                        if (pd == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfDebug = pd;
                        break;
                    }

                    case CURLoption.CURLOPT_HEADERFUNCTION:
                    {
                        HeaderFunction hf = parameter as HeaderFunction;
                        if (hf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfHeader = hf;
                        break;
                    }

                    case CURLoption.CURLOPT_SSL_CTX_FUNCTION:
                    {
                        SSLContextFunction sf = parameter as SSLContextFunction;
                        if (sf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfSSLContext = sf;
                        break;
                    }

                    case CURLoption.CURLOPT_IOCTLFUNCTION:
                    {
                        IoctlFunction iof = parameter as IoctlFunction;
                        if (iof == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfIoctl = iof;
                        break;
                    }

                    default:
                        return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                }
            }

            // otherwise, it's one of those 64-bit off_t guys!
            else
            {
                Int64 i = Convert.ToInt64(parameter);
                retCode = External.curl_easy_setopt_64(m_pCURL,
                    option, i);
            }

            return retCode;
        }
示例#16
0
文件: File.cs 项目: gclark916/banshee
 private static extern int LIBMTP_Get_File_To_File (MtpDeviceHandle handle, uint fileId, string path, ProgressFunction function, IntPtr data);
 private static extern int LIBMTP_Get_File_To_File(MtpDeviceHandle handle, uint fileId, string path, ProgressFunction function, IntPtr data);
示例#18
0
 private static extern int LIBMTP_Send_Track_From_File(MtpDeviceHandle handle, string path, ref TrackStruct track, ProgressFunction callback, IntPtr data);
示例#19
0
 private static extern IntPtr LIBMTP_Get_Tracklisting_With_Callback(MtpDeviceHandle handle, ProgressFunction callback, IntPtr data);  // LIBMTP_track_t *
示例#20
0
文件: Track.cs 项目: ptrimble/banshee
        public void Download(string path, ProgressFunction callback)
        {
            if (String.IsNullOrEmpty (path))
                throw new ArgumentException ("Cannot be null or empty", "path");

            GetTrack (device.Handle, trackStruct.item_id, path, callback, IntPtr.Zero);
        }
示例#21
0
        public List<Track> GetAllTracks(ProgressFunction callback)
        {
            IntPtr ptr = Track.GetTrackListing(Handle, callback, IntPtr.Zero);

            List<Track> tracks = new List<Track>();
            
            while (ptr != IntPtr.Zero) {
                // Destroy the struct after we use it to avoid potential referencing of freed memory.
                TrackStruct track = (TrackStruct)Marshal.PtrToStructure(ptr, typeof(TrackStruct));
                tracks.Add (new Track (track, this));
                Track.DestroyTrack (ptr);
                ptr = track.next;
            }
            
            return tracks;
        }
示例#22
0
        public void UploadTrack (string path, Track track, Folder folder, ProgressFunction callback)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");
            if (track == null)
                throw new ArgumentNullException("track");

            folder = folder ?? MusicFolder;
            if (folder != null) {
                track.trackStruct.parent_id = folder.FolderId;
            }
            
            // We send the trackstruct by ref so that when the file_id gets filled in, our copy is updated
            Track.SendTrack (Handle, path, ref track.trackStruct, callback, IntPtr.Zero);
            // LibMtp.GetStorage (Handle, 0);
        }
示例#23
0
 //progressFunctionから呼ぶ
 public void SwitchProgress(ProgressFunction function)
 {
     DeactivateAll();
     ActivateProgress(function);
     previousFunction = function;
 }
示例#24
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <exception cref="System.InvalidOperationException">This is thrown
        /// if <see cref="Curl"/> hasn't bee properly initialized.</exception>
        /// <exception cref="System.NullReferenceException">This is thrown if
        /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
		public Easy()
		{
            Curl.EnsureCurl();
            m_pCURL = External.curl_easy_init();
            EnsureHandle();
            External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_NOPROGRESS,
                IntPtr.Zero);
            m_pMyStrings = External.curl_shim_alloc_strings();
            m_pfWrite = null;
            m_privateData = null;
            m_writeData = null;
            m_pfRead = null;
            m_readData = null;
            m_pfProgress = null;
            m_progressData = null;
            m_pfDebug = null;
            m_debugData = null;
            m_pfHeader = null;
            m_headerData = null;
            m_pfSSLContext = null;
            m_sslContextData = null;
            m_pfIoctl = null;
            m_ioctlData = null;
            InstallDelegates();
        }
示例#25
0
 internal static IntPtr GetTrackListing(MtpDeviceHandle handle, ProgressFunction function, IntPtr data)
 {
     return(LIBMTP_Get_Tracklisting_With_Callback(handle, function, data));
 }
        public List<Track> GetAllTracks(ProgressFunction callback)
        {
            IntPtr ptr = Track.GetTrackListing(Handle, callback, IntPtr.Zero);

            List<Track> tracks = new List<Track>();
            
            while (ptr != IntPtr.Zero) {
                TrackStruct track = (TrackStruct)Marshal.PtrToStructure(ptr, typeof(TrackStruct));
                Track.DestroyTrack (ptr);
                tracks.Add (new Track (track, this));
                ptr = track.next;
            }
            
            return tracks;
        }
示例#27
0
 internal static void SendTrack(MtpDeviceHandle handle, string path, ref TrackStruct metadata, ProgressFunction callback, IntPtr data)
 {
     if (LIBMTP_Send_Track_From_File(handle, path, ref metadata, callback, data) != 0)
     {
         LibMtpException.CheckErrorStack(handle);
         throw new LibMtpException(ErrorCode.General, "Could not upload the track");
     }
 }
示例#28
0
文件: Track.cs 项目: ptrimble/banshee
 internal static void SendTrack(MtpDeviceHandle handle, string path, ref TrackStruct metadata, ProgressFunction callback, IntPtr data)
 {
     if (LIBMTP_Send_Track_From_File (handle, path, ref metadata, callback, data) != 0)
     {
         LibMtpException.CheckErrorStack (handle);
         throw new LibMtpException (ErrorCode.General, "Could not upload the track");
     }
 }
示例#29
0
 private static extern int LIBMTP_Get_Track_To_File(MtpDeviceHandle handle, uint trackId, string path, ProgressFunction callback, IntPtr data);
示例#30
0
文件: Track.cs 项目: ptrimble/banshee
 private static extern IntPtr LIBMTP_Get_Tracklisting_With_Callback(MtpDeviceHandle handle, ProgressFunction callback, IntPtr data);
 private static extern IntPtr LIBMTP_Get_Filelisting_With_Callback(MtpDeviceHandle handle, ProgressFunction function, IntPtr data);  // LIBMTP_file_t *
示例#32
0
文件: Track.cs 项目: ptrimble/banshee
 private static extern int LIBMTP_Get_Track_To_File(MtpDeviceHandle handle, uint trackId, string path, ProgressFunction callback, IntPtr data);
示例#33
0
文件: File.cs 项目: gclark916/banshee
 private static extern IntPtr LIBMTP_Get_Filelisting_With_Callback (MtpDeviceHandle handle, ProgressFunction function, IntPtr data); // LIBMTP_file_t *
示例#34
0
文件: Track.cs 项目: ptrimble/banshee
 private static extern int LIBMTP_Send_Track_From_File(MtpDeviceHandle handle, string path, ref TrackStruct track, ProgressFunction callback, IntPtr data);
示例#35
0
文件: Track.cs 项目: ptrimble/banshee
 internal static void GetTrack(MtpDeviceHandle handle, uint trackId, string destPath, ProgressFunction callback, IntPtr data)
 {
     if (LIBMTP_Get_Track_To_File (handle, trackId, destPath, callback, data) != 0)
     {
         LibMtpException.CheckErrorStack (handle);
         throw new LibMtpException (ErrorCode.General, "Could not download track from the device");
     }
 }
示例#36
0
 private Easy(Easy from)
 {
     m_pCURL = External.curl_easy_duphandle(from.m_pCURL);
     EnsureHandle();
     m_pMyStrings     = External.curl_shim_alloc_strings();
     m_pfWrite        = null;
     m_privateData    = null;
     m_writeData      = null;
     m_pfRead         = null;
     m_readData       = null;
     m_pfProgress     = null;
     m_progressData   = null;
     m_pfDebug        = null;
     m_debugData      = null;
     m_pfHeader       = null;
     m_headerData     = null;
     m_pfSSLContext   = null;
     m_sslContextData = null;
     m_pfIoctl        = null;
     m_ioctlData      = null;
     InstallDelegates();
 }
示例#37
0
        /// <summary>
        /// Set options for this object. See the <c>EasyGet</c> sample for
        /// basic usage.
        /// </summary>
        /// <param name="option">This should be a valid <see cref="CURLoption"/>.</param>
        /// <param name="parameter">This should be a parameter of a varying
        /// type based on the value of the <c>option</c> parameter.</param>
        /// <exception cref="System.NullReferenceException">This is thrown if
        /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
        /// <returns>A <see cref="CURLcode"/>, typically obtained from
        /// <c>cURL</c> internally, but sometimes a
        /// <see cref="CURLcode.CURLE_BAD_FUNCTION_ARGUMENT"/>
        /// will be returned if the type of value of <c>parameter</c> is invalid.
        /// </returns>
        public CURLcode SetOpt(CURLoption option, Object parameter)
        {
            EnsureHandle();
            CURLcode retCode = CURLcode.CURLE_OK;

            // numeric cases
            if ((int)option < CURLOPTTYPE_OBJECTPOINT)
            {
                int i = 0;
                if (option == CURLoption.CURLOPT_DNS_USE_GLOBAL_CACHE ||
                    option == CURLoption.CURLOPT_SOURCE_PORT)
                {
                    return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                }
                else if (option == CURLoption.CURLOPT_TIMEVALUE)
                {
                    // unboxing may throw class cast exception
                    //DateTime d = (DateTime)parameter;
                    DateTime startTime = Main.DateTimeBegin;
                    TimeSpan currTime  = new TimeSpan(DateTime.Now.Ticks - startTime.Ticks);
                    i = Convert.ToInt32(currTime.TotalSeconds);
                }
                else
                {
                    i = Convert.ToInt32(parameter);
                }

                retCode = External.curl_easy_setopt_int(m_pCURL,
                                                        option, i);
            }

            // object cases: the majority
            else if ((int)option < CURLOPTTYPE_FUNCTIONPOINT)
            {
                switch (option)
                {
                // various data items
                case CURLoption.CURLOPT_PRIVATE:
                    m_privateData = parameter; break;

                case CURLoption.CURLOPT_WRITEDATA:
                    m_writeData = parameter; break;

                case CURLoption.CURLOPT_READDATA:
                    m_readData = parameter; break;

                case CURLoption.CURLOPT_PROGRESSDATA:
                    m_progressData = parameter; break;

                case CURLoption.CURLOPT_DEBUGDATA:
                    m_debugData = parameter; break;

                case CURLoption.CURLOPT_HEADERDATA:
                    m_headerData = parameter; break;

                case CURLoption.CURLOPT_SSL_CTX_DATA:
                    m_sslContextData = parameter; break;

                case CURLoption.CURLOPT_IOCTLDATA:
                    m_ioctlData = parameter; break;

                // items that can't be set externally or
                // obsolete items
                case CURLoption.CURLOPT_ERRORBUFFER:
                case CURLoption.CURLOPT_STDERR:
                case CURLoption.CURLOPT_SOURCE_HOST:
                case CURLoption.CURLOPT_SOURCE_PATH:
                case CURLoption.CURLOPT_PASV_HOST:
                    return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);

                // singular case for share
                case CURLoption.CURLOPT_SHARE:
                {
                    Share share = parameter as Share;
                    if (share == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                            option, share.GetHandle());
                    break;
                }

                // multipart HTTP post
                case CURLoption.CURLOPT_HTTPPOST:
                {
                    MultiPartForm mf = parameter as MultiPartForm;
                    if (mf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                            option, mf.GetHandle());
                    break;
                }

                // items curl wants as a curl_slist
                case CURLoption.CURLOPT_HTTPHEADER:
                case CURLoption.CURLOPT_PREQUOTE:
                case CURLoption.CURLOPT_QUOTE:
                case CURLoption.CURLOPT_POSTQUOTE:
                case CURLoption.CURLOPT_SOURCE_QUOTE:
                case CURLoption.CURLOPT_TELNETOPTIONS:
                case CURLoption.CURLOPT_HTTP200ALIASES:
                {
                    Slist slist = parameter as Slist;
                    if (slist == null)
                    {
                        retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                option, IntPtr.Zero);
                    }
                    else
                    {
                        retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                option, slist.GetHandle());
                    }
                    break;
                }

                // string items
                default:
                {
                    string s = parameter as string;
                    if (s == null)
                    {
                        retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                option, IntPtr.Zero);
                    }
                    else
                    {
                        IntPtr pCurlStr = External.curl_shim_add_string(
                            m_pMyStrings, s);
                        if (pCurlStr != IntPtr.Zero)
                        {
                            retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                    option, pCurlStr);
                        }
                    }
                    break;
                }
                }
            }

            // FUNCTIONPOINT args, for delegates
            else if ((int)option < CURLOPTTYPE_OFF_T)
            {
                switch (option)
                {
                case CURLoption.CURLOPT_WRITEFUNCTION:
                {
                    WriteFunction wf = parameter as WriteFunction;
                    if (wf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfWrite = wf;
                    break;
                }

                case CURLoption.CURLOPT_READFUNCTION:
                {
                    ReadFunction rf = parameter as ReadFunction;
                    if (rf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfRead = rf;
                    break;
                }

                case CURLoption.CURLOPT_PROGRESSFUNCTION:
                {
                    ProgressFunction pf = parameter as ProgressFunction;
                    if (pf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfProgress = pf;
                    break;
                }

                case CURLoption.CURLOPT_DEBUGFUNCTION:
                {
                    DebugFunction pd = parameter as DebugFunction;
                    if (pd == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfDebug = pd;
                    break;
                }

                case CURLoption.CURLOPT_HEADERFUNCTION:
                {
                    HeaderFunction hf = parameter as HeaderFunction;
                    if (hf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfHeader = hf;
                    break;
                }

                case CURLoption.CURLOPT_SSL_CTX_FUNCTION:
                {
                    SSLContextFunction sf = parameter as SSLContextFunction;
                    if (sf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfSSLContext = sf;
                    break;
                }

                case CURLoption.CURLOPT_IOCTLFUNCTION:
                {
                    IoctlFunction iof = parameter as IoctlFunction;
                    if (iof == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfIoctl = iof;
                    break;
                }

                default:
                    return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                }
            }

            // otherwise, it's one of those 64-bit off_t guys!
            else
            {
                Int64 i = Convert.ToInt64(parameter);
                retCode = External.curl_easy_setopt_int64(m_pCURL,
                                                          option, i);
            }

            return(retCode);
        }
示例#38
0
文件: Track.cs 项目: ptrimble/banshee
 internal static IntPtr GetTrackListing(MtpDeviceHandle handle, ProgressFunction function, IntPtr data)
 {
     return LIBMTP_Get_Tracklisting_With_Callback (handle, function, data);
 }