コード例 #1
0
        /// <summary>
        /// CopyFile wrapper that attempts to use CopyFile2 if running as Windows Store app.
        /// </summary>
        public static void CopyFile(string source, string destination, bool overwrite = false)
        {
            // Prefer CreateFile2, falling back to CreateFileEx if we can
            if (s_copyFileDelegate == null)
            {
                s_copyFileDelegate = CopyFile2;
                try
                {
                    s_copyFileDelegate(source, destination, overwrite);
                    return;
                }
                catch (Exception exception)
                {
                    // Any error other than EntryPointNotFound we've found CreateFile2, rethrow
                    if (!ErrorHelper.IsEntryPointNotFoundException(exception))
                    {
                        throw;
                    }

                    s_copyFileDelegate = Delegates.CreateDelegate <CopyFileDelegate>(
                        "WInterop.FileManagement.Desktop.NativeMethods, " + Delegates.DesktopLibrary,
                        "CopyFileEx");
                }
            }

            s_copyFileDelegate(source, destination, overwrite);
        }
コード例 #2
0
ファイル: Storage.cs プロジェクト: daxiang758/WInterop
        /// <summary>
        /// CopyFile wrapper that attempts to use CopyFile2 if running as Windows Store app.
        /// </summary>
        public static void CopyFile(string source, string destination, bool overwrite = false)
        {
            // Prefer CreateFile2, falling back to CreateFileEx if we can
            if (s_copyFileDelegate == null)
            {
                s_copyFileDelegate = CopyFile2;
                try
                {
                    s_copyFileDelegate(source, destination, overwrite);
                    return;
                }
                catch (EntryPointNotFoundException)
                {
                    s_copyFileDelegate = Delegates.CreateDelegate <CopyFileDelegate>(
                        "WInterop.Storage.Desktop.NativeMethods, " + Delegates.DesktopLibrary,
                        "CopyFileEx");
                }
            }

            s_copyFileDelegate(source, destination, overwrite);
        }
コード例 #3
0
 private void BeginThreads()
 {
     while (InProgressActions.Count < MaxActions)
     {
         // Pop a pending action off the queue.
         SyncOperation op;
         lock (PendingFileActions)
         {
             op = PendingFileActions.Dequeue();
         }
         // Kick off a thread.
         switch (op.Action)
         {
             case SyncOperation.SyncAction.Copy:
                 CopyFileDelegate cf = new CopyFileDelegate(File.Copy);
                 lock (InProgressActions)
                 {
                     InProgressActions.Add(cf.BeginInvoke(op.SourceFile, op.TargetFile, FinishAction, cf));
                 }
                 break;
             case SyncOperation.SyncAction.Delete:
                 if (Directory.Exists(op.SourceFile))
                 {
                     DeleteDirectoryDelegate dd = new DeleteDirectoryDelegate(Directory.Delete);
                     lock (InProgressActions)
                     {
                         InProgressActions.Add(dd.BeginInvoke(op.SourceFile, FinishAction, dd));
                     }
                 }
                 else if (File.Exists(op.SourceFile))
                 {
                     DeleteFileDelegate df = new DeleteFileDelegate(File.Delete);
                     lock (InProgressActions)
                     {
                         InProgressActions.Add(df.BeginInvoke(op.SourceFile, FinishAction, df));
                     }
                 }
                 break;
             case SyncOperation.SyncAction.Move:
                 MoveFileDelegate mf = new MoveFileDelegate(File.Move);
                 lock (InProgressActions)
                 {
                     InProgressActions.Add(mf.BeginInvoke(op.SourceFile, op.TargetFile, FinishAction, mf));
                 }
                 break;
             default:
                 break;
         }
     }
 }