コード例 #1
0
ファイル: FileConverter.cs プロジェクト: jpires/gta2net
        private void ConvertFiles(string sourcePath, string destinationPath, CancellableContext asyncContext, out bool cancelled)
        {
            cancelled = false;

            CreateSubDirectories(destinationPath);

            //convert style files
            for (int i = 0; i < Globals.StyleMapFiles.Length; i++)
            {
                var styleFile = Globals.StyleMapFiles[i];
                if (asyncContext.IsCancelling)
                {
                    cancelled = true;
                    return;
                }
                //copy over style file (because some data in it are still needed)
                var style = new Style.Style();
                var sourceFile = sourcePath + Globals.DataSubDir + Path.DirectorySeparatorChar + styleFile + Globals.StyleFileExtension;
                var targetFile = destinationPath + Globals.GraphicsSubDir + Path.DirectorySeparatorChar + styleFile + Globals.StyleFileExtension;
                if (!File.Exists(targetFile) || !Extensions.FilesAreEqual(sourceFile, targetFile))
                    File.Copy(sourceFile, targetFile, true);
                style.ConvertStyleFileCompleted += StyleOnConvertStyleFileCompleted;
                style.ReadFromFileAsync(targetFile, i == 0);
                _runningStyles.Add(style);
            }

            //copy over maps
            var mapFiles = Globals.StyleMapFiles.Select(mapFile => sourcePath + Globals.DataSubDir + Path.DirectorySeparatorChar + mapFile + Globals.MapFileExtension).ToList();
            mapFiles.AddRange(Globals.MapFilesMultiplayer.Select(multiplayerMapFile => sourcePath + Globals.DataSubDir + Path.DirectorySeparatorChar + multiplayerMapFile + Globals.MapFileExtension));
            for (var i = 0; i < mapFiles.Count; i++)
            {
                if (asyncContext.IsCancelling)
                {
                    cancelled = true;
                    return;
                }
                var targetFile = destinationPath + Globals.MapsSubDir + Path.DirectorySeparatorChar + Path.GetFileName(mapFiles[i]);
                if (File.Exists(targetFile))
                {
                    if (Extensions.FilesAreEqual(mapFiles[i], targetFile))
                        continue;
                }
                File.Copy(mapFiles[i], targetFile, true);
            }

            var miscFiles = Globals.MiscFiles.Select(miscFile => sourcePath + Globals.DataSubDir + Path.DirectorySeparatorChar + miscFile).ToList();
            for (var i = 0; i < miscFiles.Count; i++)
            {
                if (asyncContext.IsCancelling)
                {
                    cancelled = true;
                    return;
                }
                var targetFile = destinationPath + Globals.MiscSubDir + Path.DirectorySeparatorChar + Path.GetFileName(miscFiles[i]);
                if (File.Exists(targetFile))
                {
                    if (Extensions.FilesAreEqual(miscFiles[i], targetFile))
                        continue;
                }
                File.Copy(miscFiles[i], targetFile, true);
            }

            WaitHandle.WaitOne();
            IndexFile.Save();
            cancelled = WaitHandle.Value;
        }
コード例 #2
0
ファイル: FileConverter.cs プロジェクト: jpires/gta2net
        public void ConvertFilesAsync(string sourcePath, string destinationPath)
        {
            sourcePath = Extensions.CheckDirectorySeparator(sourcePath);
            destinationPath = Extensions.CheckDirectorySeparator(destinationPath);
            var worker = new ConvertFilesDelegate(ConvertFiles);
            var completedCallback = new AsyncCallback(ConversionCompletedCallback);

            lock (_syncCancel)
            {
                if (_isBusy)
                    throw new InvalidOperationException("The control is currently busy.");

                var async = AsyncOperationManager.CreateOperation(null);
                var context = new CancellableContext(async);
                bool cancelled;

                worker.BeginInvoke(sourcePath, destinationPath, context, out cancelled, completedCallback, async);

                _isBusy = true;
                _convertFilesContext = context;
            }
        }
コード例 #3
0
ファイル: FileConverter.cs プロジェクト: jpires/gta2net
        private void ConversionCompletedCallback(IAsyncResult ar)
        {
            // get the original worker delegate and the AsyncOperation instance
            var worker = (ConvertFilesDelegate)((AsyncResult)ar).AsyncDelegate;
            var async = (AsyncOperation)ar.AsyncState;
            bool cancelled;

            // finish the asynchronous operation
            worker.EndInvoke(out cancelled, ar);

            // clear the running task flag
            lock (_syncCancel)
            {
                _isBusy = false;
                _convertFilesContext = null;
            }

            // raise the completed event
            var completedArgs = new AsyncCompletedEventArgs(null, cancelled, null);
            async.PostOperationCompleted(e => OnConversionCompleted((AsyncCompletedEventArgs)e), completedArgs);
        }
コード例 #4
0
ファイル: FileConverter.cs プロジェクト: jpires/gta2net
 public void ConvertFiles(string sourcePath, string destinationPath)
 {
     var context = new CancellableContext(null);
     bool cancelled;
     ConvertFiles(sourcePath, destinationPath, context, out cancelled);
 }