Example #1
0
        private static async Task MainAsync()
        {
            var saveFile = await SaveDirectory.OpenFileAsync(SaveDirectory.DebugGame);

            using (new TcpServer(new Universe(saveFile, DataLoader.LoadMod("Core")), true))
            {
                Console.WriteLine("Server running, press Q to quit.");
                while (Console.ReadKey(true).Key != ConsoleKey.Q)
                {
                }
            }
        }
 public bool LoadDirectory()
 {
     SaveDirectory.Refresh();
     if (SaveDirectory.Exists)
     {
         var files = SaveDirectory.GetFiles("*.json");
         if (files.Any(x => x.Name == PlayerChestFileName) && files.Any(x => x.Name == PlayerDataFileName))
         {
             if (SaveDirectory.GetDirectories().Any(x => x.Name == CharactersDirectoryName))
             {
                 var charFiles = SaveDirectory.EnumerateDirectories().Single(x => x.Name == CharactersDirectoryName)
                                 .GetFiles("*.json");
                 foreach (var charFile in charFiles)
                 {
                     LoadCharacter(charFile);
                 }
                 Status = FileBackupStatus.Loaded;
                 return(true);
             }
         }
     }
     Status = FileBackupStatus.Error;
     return(false);
 }
Example #3
0
        public async Task LoadGameAsync(string name)
        {
            Disconnect();

            IsConnecting = true;
            try
            {
                var saveFile = await SaveDirectory.OpenFileAsync(SaveDirectory.DebugGame);

                var server = await Task.Run(() => new TcpServer(new GameHost(new Universe(saveFile), DataLoader.LoadMod("Core")), true));

                _server = server;

                var channel = await ConnectTcpAsync("127.0.0.1", server.Port);
                await ConnectChannelAsync(channel);
            }
            catch
            {
            }
            finally
            {
                IsConnecting = false;
            }
        }
Example #4
0
        public SaveMapLogic(Widget widget, ModData modData, Action <string> onSave, Action onExit,
                            Map map, List <MiniYamlNode> playerDefinitions, List <MiniYamlNode> actorDefinitions)
        {
            var title = widget.Get <TextFieldWidget>("TITLE");

            title.Text = map.Title;

            var author = widget.Get <TextFieldWidget>("AUTHOR");

            author.Text = map.Author;

            var visibilityPanel   = Ui.LoadWidget("MAP_SAVE_VISIBILITY_PANEL", null, new WidgetArgs());
            var visOptionTemplate = visibilityPanel.Get <CheckboxWidget>("VISIBILITY_TEMPLATE");

            visibilityPanel.RemoveChildren();

            foreach (MapVisibility visibilityOption in Enum.GetValues(typeof(MapVisibility)))
            {
                // To prevent users from breaking the game only show the 'Shellmap' option when it is already set.
                if (visibilityOption == MapVisibility.Shellmap && !map.Visibility.HasFlag(visibilityOption))
                {
                    continue;
                }

                var checkbox = (CheckboxWidget)visOptionTemplate.Clone();
                checkbox.GetText   = () => visibilityOption.ToString();
                checkbox.IsChecked = () => map.Visibility.HasFlag(visibilityOption);
                checkbox.OnClick   = () => map.Visibility ^= visibilityOption;
                visibilityPanel.AddChild(checkbox);
            }

            var visibilityDropdown = widget.Get <DropDownButtonWidget>("VISIBILITY_DROPDOWN");

            visibilityDropdown.OnMouseDown = _ =>
            {
                visibilityDropdown.RemovePanel();
                visibilityDropdown.AttachPanel(visibilityPanel);
            };

            var           writableDirectories = new List <SaveDirectory>();
            SaveDirectory selectedDirectory   = null;

            var directoryDropdown = widget.Get <DropDownButtonWidget>("DIRECTORY_DROPDOWN");
            {
                Func <SaveDirectory, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => selectedDirectory == option,
                                                      () => selectedDirectory = option);
                    item.Get <LabelWidget>("LABEL").GetText = () => option.DisplayName;
                    return(item);
                };

                foreach (var kv in modData.MapCache.MapLocations)
                {
                    var folder = kv.Key as Folder;
                    if (folder == null)
                    {
                        continue;
                    }

                    try
                    {
                        using (var fs = File.Create(Path.Combine(folder.Name, ".testwritable"), 1, FileOptions.DeleteOnClose))
                        {
                            // Do nothing: we just want to test whether we can create the file
                        }

                        writableDirectories.Add(new SaveDirectory(folder, kv.Value.ToString(), kv.Value));
                    }
                    catch
                    {
                        // Directory is not writable
                    }
                }

                if (map.Package != null)
                {
                    selectedDirectory = writableDirectories.FirstOrDefault(k => k.Folder.Contains(map.Package.Name));
                    if (selectedDirectory == null)
                    {
                        selectedDirectory = writableDirectories.FirstOrDefault(k => Directory.GetDirectories(k.Folder.Name).Any(f => f.Contains(map.Package.Name)));
                    }
                }

                // Prioritize MapClassification.User directories over system directories
                if (selectedDirectory == null)
                {
                    selectedDirectory = writableDirectories.OrderByDescending(kv => kv.Classification).First();
                }

                directoryDropdown.GetText = () => selectedDirectory?.DisplayName ?? "";
                directoryDropdown.OnClick = () =>
                                            directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, writableDirectories, setupItem);
            }

            var mapIsUnpacked = map.Package != null && map.Package is Folder;

            var filename = widget.Get <TextFieldWidget>("FILENAME");

            filename.Text = map.Package == null ? "" : mapIsUnpacked?Path.GetFileName(map.Package.Name) : Path.GetFileNameWithoutExtension(map.Package.Name);

            var fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap;

            var fileTypes = new Dictionary <MapFileType, MapFileTypeInfo>()
            {
                { MapFileType.OraMap, new MapFileTypeInfo {
                      Extension = ".oramap", UiLabel = ".oramap"
                  } },
                { MapFileType.Unpacked, new MapFileTypeInfo {
                      Extension = "", UiLabel = "(unpacked)"
                  } }
            };

            var typeDropdown = widget.Get <DropDownButtonWidget>("TYPE_DROPDOWN");
            {
                Func <KeyValuePair <MapFileType, MapFileTypeInfo>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => fileType == option.Key,
                                                      () => { typeDropdown.Text = option.Value.UiLabel; fileType = option.Key; });
                    item.Get <LabelWidget>("LABEL").GetText = () => option.Value.UiLabel;
                    return(item);
                };

                typeDropdown.Text = fileTypes[fileType].UiLabel;

                typeDropdown.OnClick = () =>
                                       typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes, setupItem);
            }

            var close = widget.Get <ButtonWidget>("BACK_BUTTON");

            close.OnClick = () => { Ui.CloseWindow(); onExit(); };

            var save = widget.Get <ButtonWidget>("SAVE_BUTTON");

            save.OnClick = () =>
            {
                if (string.IsNullOrEmpty(filename.Text))
                {
                    return;
                }

                map.Title  = title.Text;
                map.Author = author.Text;

                if (actorDefinitions != null)
                {
                    map.ActorDefinitions = actorDefinitions;
                }

                if (playerDefinitions != null)
                {
                    map.PlayerDefinitions = playerDefinitions;
                }

                map.RequiresMod = modData.Manifest.Id;

                var combinedPath = Platform.ResolvePath(Path.Combine(selectedDirectory.Folder.Name, filename.Text + fileTypes[fileType].Extension));

                try
                {
                    if (!(map.Package is IReadWritePackage package) || package.Name != combinedPath)
                    {
                        selectedDirectory.Folder.Delete(combinedPath);
                        if (fileType == MapFileType.OraMap)
                        {
                            package = ZipFileLoader.Create(combinedPath);
                        }
                        else
                        {
                            package = new Folder(combinedPath);
                        }
                    }

                    map.Save(package);

                    Console.WriteLine("Saved current map at {0}", combinedPath);
                    Ui.CloseWindow();

                    onSave(map.Uid);
                }
                catch (Exception e)
                {
                    Log.Write("debug", "Failed to save map at {0}: {1}", combinedPath, e.Message);
                    Log.Write("debug", "{0}", e.StackTrace);

                    ConfirmationDialogs.ButtonPrompt(
                        title: "Failed to save map",
                        text: "See debug.log for details.",
                        onConfirm: () => { },
                        confirmText: "OK");
                }
            };
        }
Example #5
0
        public void WriteXml(System.Xml.XmlWriter writer)
        {
            var s = new XmlSerializer(typeof(string));
            var b = new XmlSerializer(typeof(bool));
            var l = new XmlSerializer(typeof(List <AutoAnswer>));

            writer.WriteStartElement("TaskInfo");

            //taskid
            writer.WriteStartElement("TaskId");
            s.Serialize(writer, TaskId.ToString());
            writer.WriteEndElement();

            //pluginname
            writer.WriteStartElement("PluginName");
            s.Serialize(writer, PluginName);
            writer.WriteEndElement();

            //url
            writer.WriteStartElement("Url");
            s.Serialize(writer, Url);
            writer.WriteEndElement();

            //title
            writer.WriteStartElement("Title");
            s.Serialize(writer, Title);
            writer.WriteEndElement();

            //status
            writer.WriteStartElement("Status");
            DownloadStatus tmpds = Status;

            if (tmpds == DownloadStatus.正在下载 || tmpds == DownloadStatus.正在停止 || tmpds == DownloadStatus.等待开始)
            {
                tmpds = DownloadStatus.已经停止;
            }
            s.Serialize(writer, tmpds.ToString());
            writer.WriteEndElement();

            //createtime
            writer.WriteStartElement("CreateTime");
            s.Serialize(writer, CreateTime.ToString());
            writer.WriteEndElement();

            //finishtime
            if (FinishTime != null)
            {
                writer.WriteStartElement("FinishTime");
                s.Serialize(writer, FinishTime.ToString());
                writer.WriteEndElement();
            }

            //savedirectory
            writer.WriteStartElement("SaveDirectory");
            s.Serialize(writer, SaveDirectory.ToString());
            writer.WriteEndElement();

            //PartCount
            writer.WriteStartElement("PartCount");
            s.Serialize(writer, PartCount.ToString());
            writer.WriteEndElement();

            //CurrentPart
            writer.WriteStartElement("CurrentPart");
            s.Serialize(writer, CurrentPart.ToString());
            writer.WriteEndElement();

            //is be added
            writer.WriteStartElement("IsBeAdded");
            b.Serialize(writer, IsBeAdded);
            writer.WriteEndElement();

            //partialfinished
            writer.WriteStartElement("PartialFinished");
            b.Serialize(writer, PartialFinished);
            writer.WriteEndElement();

            //partialfinished detail
            writer.WriteStartElement("PartialFinishedDetail");
            s.Serialize(writer, PartialFinishedDetail);
            writer.WriteEndElement();

            //autoanswer
            writer.WriteStartElement("AutoAnswers");
            l.Serialize(writer, AutoAnswer);
            writer.WriteEndElement();

            //extract cache
            writer.WriteStartElement("ExtractCache");
            b.Serialize(writer, ExtractCache);
            writer.WriteEndElement();

            //FilePath
            writer.WriteStartElement("Files");
            foreach (string item in FilePath)
            {
                writer.WriteStartElement("File");
                s.Serialize(writer, item);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            //SubFilePath
            writer.WriteStartElement("SubFiles");
            foreach (string item in SubFilePath)
            {
                writer.WriteStartElement("SubFile");
                s.Serialize(writer, item);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            //DownloadType
            writer.WriteStartElement("DownloadType");
            s.Serialize(writer, DownloadTypes.ToString("D"));
            writer.WriteEndElement();

            //proxy
            XmlSerializer sProxy = new XmlSerializer(typeof(AcDownProxy));

            writer.WriteStartElement("Proxy");
            sProxy.Serialize(writer, new AcDownProxy().FromWebProxy(Proxy));
            writer.WriteEndElement();

            //source url
            writer.WriteStartElement("SourceUrl");
            s.Serialize(writer, SourceUrl);
            writer.WriteEndElement();

            //comment
            writer.WriteStartElement("Comment");
            s.Serialize(writer, Comment);
            writer.WriteEndElement();

            //hash
            writer.WriteStartElement("Hash");
            s.Serialize(writer, Hash);
            writer.WriteEndElement();

            //Progress
            writer.WriteStartElement("Progress");
            s.Serialize(writer, GetProgress().ToString());
            writer.WriteEndElement();

            //settings
            XmlSerializer sSettings = new XmlSerializer(typeof(SerializableDictionary <string, string>));

            writer.WriteStartElement("Settings");
            sSettings.Serialize(writer, Settings);
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
Example #6
0
 private void loadSavedChart(string name) =>
 load(SaveDirectory.Join(name + Ext));
Example #7
0
 private IEnumerable <string> getSavedCharts()
 {
     return(SaveDirectory.EnumerateFiles("*" + Ext)
            .Select(_ => _.Basename(extension: false)));
 }
Example #8
0
        public SaveMapLogic(Widget widget, ModData modData, Action <string> onSave, Action onExit,
                            Map map, List <MiniYamlNode> playerDefinitions, List <MiniYamlNode> actorDefinitions)
        {
            var title = widget.Get <TextFieldWidget>("TITLE");

            title.Text = map.Title;

            var author = widget.Get <TextFieldWidget>("AUTHOR");

            author.Text = map.Author;

            // TODO: This should use a multi-selection dropdown once they exist
            var visibilityDropdown = widget.Get <DropDownButtonWidget>("VISIBILITY_DROPDOWN");
            {
                var mapVisibility = new List <string>(Enum.GetNames(typeof(MapVisibility)));
                Func <string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => visibilityDropdown.Text == option,
                                                      () => { visibilityDropdown.Text = option; });
                    item.Get <LabelWidget>("LABEL").GetText = () => option;
                    return(item);
                };

                visibilityDropdown.Text    = Enum.GetName(typeof(MapVisibility), map.Visibility);
                visibilityDropdown.OnClick = () =>
                                             visibilityDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapVisibility, setupItem);
            }

            var           writableDirectories = new List <SaveDirectory>();
            SaveDirectory selectedDirectory   = null;

            var directoryDropdown = widget.Get <DropDownButtonWidget>("DIRECTORY_DROPDOWN");
            {
                Func <SaveDirectory, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => selectedDirectory == option,
                                                      () => selectedDirectory = option);
                    item.Get <LabelWidget>("LABEL").GetText = () => option.DisplayName;
                    return(item);
                };

                foreach (var kv in modData.MapCache.MapLocations)
                {
                    var folder = kv.Key as Folder;
                    if (folder == null)
                    {
                        continue;
                    }

                    try
                    {
                        using (var fs = File.Create(Path.Combine(folder.Name, ".testwritable"), 1, FileOptions.DeleteOnClose))
                        {
                            // Do nothing: we just want to test whether we can create the file
                        }

                        writableDirectories.Add(new SaveDirectory(folder, kv.Value));
                    }
                    catch
                    {
                        // Directory is not writable
                    }
                }

                if (map.Package != null)
                {
                    selectedDirectory = writableDirectories.FirstOrDefault(k => k.Folder.Contains(map.Package.Name));
                }

                // Prioritize MapClassification.User directories over system directories
                if (selectedDirectory == null)
                {
                    selectedDirectory = writableDirectories.OrderByDescending(kv => kv.Classification).First();
                }

                directoryDropdown.GetText = () => selectedDirectory == null ? "" : selectedDirectory.DisplayName;
                directoryDropdown.OnClick = () =>
                                            directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, writableDirectories, setupItem);
            }

            var mapIsUnpacked = map.Package != null && (map.Package is Folder || map.Package is ZipFolder);

            var filename = widget.Get <TextFieldWidget>("FILENAME");

            filename.Text = map.Package == null ? "" : mapIsUnpacked?Path.GetFileName(map.Package.Name) : Path.GetFileNameWithoutExtension(map.Package.Name);

            var fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap;

            var fileTypes = new Dictionary <MapFileType, MapFileTypeInfo>()
            {
                { MapFileType.OraMap, new MapFileTypeInfo {
                      Extension = ".oramap", UiLabel = ".oramap"
                  } },
                { MapFileType.Unpacked, new MapFileTypeInfo {
                      Extension = "", UiLabel = "(unpacked)"
                  } }
            };

            var typeDropdown = widget.Get <DropDownButtonWidget>("TYPE_DROPDOWN");
            {
                Func <KeyValuePair <MapFileType, MapFileTypeInfo>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => fileType == option.Key,
                                                      () => { typeDropdown.Text = option.Value.UiLabel; fileType = option.Key; });
                    item.Get <LabelWidget>("LABEL").GetText = () => option.Value.UiLabel;
                    return(item);
                };

                typeDropdown.Text = fileTypes[fileType].UiLabel;

                typeDropdown.OnClick = () =>
                                       typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes, setupItem);
            }

            var close = widget.Get <ButtonWidget>("BACK_BUTTON");

            close.OnClick = () => { Ui.CloseWindow(); onExit(); };

            var save = widget.Get <ButtonWidget>("SAVE_BUTTON");

            save.OnClick = () =>
            {
                if (string.IsNullOrEmpty(filename.Text))
                {
                    return;
                }

                map.Title      = title.Text;
                map.Author     = author.Text;
                map.Visibility = (MapVisibility)Enum.Parse(typeof(MapVisibility), visibilityDropdown.Text);

                if (actorDefinitions != null)
                {
                    map.ActorDefinitions = actorDefinitions;
                }

                if (playerDefinitions != null)
                {
                    map.PlayerDefinitions = playerDefinitions;
                }

                map.RequiresMod = modData.Manifest.Mod.Id;

                var combinedPath = Platform.ResolvePath(Path.Combine(selectedDirectory.Folder.Name, filename.Text + fileTypes[fileType].Extension));

                // Invalidate the old map metadata
                if (map.Uid != null && map.Package != null && map.Package.Name == combinedPath)
                {
                    modData.MapCache[map.Uid].Invalidate();
                }

                try
                {
                    var package = map.Package as IReadWritePackage;
                    if (package == null || package.Name != combinedPath)
                    {
                        selectedDirectory.Folder.Delete(combinedPath);
                        if (fileType == MapFileType.OraMap)
                        {
                            package = new ZipFile(modData.DefaultFileSystem, combinedPath, true);
                        }
                        else
                        {
                            package = new Folder(combinedPath);
                        }
                    }

                    map.Save(package);
                }
                catch
                {
                    Console.WriteLine("Failed to save map at {0}", combinedPath);
                }

                // Update the map cache so it can be loaded without restarting the game
                modData.MapCache[map.Uid].UpdateFromMap(map.Package, selectedDirectory.Folder, selectedDirectory.Classification, null, map.Grid.Type);

                Console.WriteLine("Saved current map at {0}", combinedPath);
                Ui.CloseWindow();

                onSave(map.Uid);
            };
        }
Example #9
0
        public String Publish(bool commandLine = false)
        {
            #region Publish Flag
            if (File.Exists(commandLine?String.Format("C:\\Temp\\{0}", flagFileName):Server == null?flagFileName:Server.MapPath(flagFileName)))
            {
                State.log.WriteLine("Flag file {0} already exists... checking timestamp", flagFileName);
                String data  = (new StreamReader(new FileStream(commandLine ? String.Format("C:\\Temp\\{0}", flagFileName) : Server == null ?  flagFileName : Server.MapPath(flagFileName), FileMode.Open))).ReadLine();
                long   ticks = 0;
                try
                {
                    ticks = Convert.ToInt64(data);
                }
                catch
                {
                    // ignore... zero will do!
                    State.log.WriteLine("Flag file is incomplete.  Ignoring.");
                    WebhostEventLog.CommentLog.LogWarning("Flag file {0} is incomplete.  Ignoring.", flagFileName);
                }

                if (DateTime.Now.AddMinutes(2).Ticks < ticks)
                {
                    File.Delete(Server == null ? flagFileName : Server.MapPath(flagFileName));
                    State.log.WriteLine("Deleting Extraneous Old Flag File.");
                    WebhostEventLog.CommentLog.LogWarning("Deleting timed out flag file {0}", flagFileName);
                }
                else
                {
                    State.log.WriteLine("This file is Busy! Be Patient!");
                    throw new CommentException("Comment is already Publishing! Be Patient!");
                }
            }

            StreamWriter writer = new StreamWriter(new FileStream(commandLine ? String.Format("C:\\Temp\\{0}", flagFileName) : Server == null ? flagFileName : Server.MapPath(flagFileName), FileMode.Create));
            writer.WriteLine(DateTime.Now.Ticks);
            writer.Close();
            #endregion  // Publish flag

            document.Add(HeaderTable);
            document.Add(StudentAdvisorClassTable);
            document.Add(GradesBar);

            foreach (Paragraph paragraph in ClassHeaderParagraphs)
            {
                // if (!whiteSpace.IsMatch(paragraph.Content))
                document.Add(paragraph);
            }
            foreach (Paragraph paragraph in StudentCommentParagraph)
            {
                //  if (!whiteSpace.IsMatch(paragraph.Content))
                document.Add(paragraph);
            }
            document.Add(SignatureLine);

            File.Delete(commandLine ? String.Format("C:\\Temp\\{0}", flagFileName) : SaveDirectory.Equals("")? Server.MapPath(flagFileName):flagFileName);

            if (commandLine)
            {
                base.Publish();
                return(FileName);
            }

            return(base.Publish());
        }
Example #10
0
        //下载视频
        public void Download()
        {
            //开始下载
            delegates.Start(new ParaStart(this.TaskId));
            delegates.TipText(new ParaTipText(this.TaskId, "正在分析视频地址"));
            _status = DownloadStatus.正在下载;
            try
            {
                //获取密码
                string password = "";
                if (Url.EndsWith("密码"))
                {
                    password = ToolForm.CreatePasswordForm(true, "", "");
                }

                //取得网页源文件
                string src = Network.GetHtmlSource(Url.Replace("密码", ""), Encoding.UTF8, delegates.Proxy);

                //分析视频evid
                string evid = "";

                //取得evid
                Regex r1 = new Regex(@"evid = '(?<evid>.+)'");
                Match m1 = r1.Match(src);
                evid = m1.Groups["evid"].ToString();

                //取得视频标题
                Regex  rTitle = new Regex(@"<h(1|2) class=$(vt|pvt)$>(?<title>.+?)<".Replace("$", "\""));
                Match  mTitle = rTitle.Match(src);
                string title  = mTitle.Groups["title"].Value;
                //过滤非法字符
                title  = Tools.InvalidCharacterFilter(title, "");
                _title = title;

                //视频地址数组
                string[] videos = null;
                //清空地址
                _filePath.Clear();

                //调用内建的土豆视频解析器
                SixcnParser parserSixcn = new SixcnParser();
                videos = parserSixcn.Parse(new string[] { evid, password }, delegates.Proxy);

                //下载视频
                //确定视频共有几个段落
                _partCount = videos.Length;

                //分段落下载
                for (int i = 0; i < _partCount; i++)
                {
                    _currentPart = i + 1;
                    //提示更换新Part
                    delegates.NewPart(new ParaNewPart(this.TaskId, i + 1));
                    //取得文件后缀名
                    string ext = Tools.GetExtension(videos[i]);
                    //设置当前DownloadParameter
                    if (_partCount == 1)                     //如果只有一段
                    {
                        currentParameter = new DownloadParameter()
                        {
                            //文件名 例: c:\123(1).flv
                            FilePath = Path.Combine(SaveDirectory.ToString(),
                                                    _title + "." + ext),
                            //文件URL
                            Url = videos[i]
                        };
                    }
                    else                     //如果分段有多段
                    {
                        currentParameter = new DownloadParameter()
                        {
                            //文件名 例: c:\123(1).flv
                            FilePath = Path.Combine(SaveDirectory.ToString(),
                                                    _title + "(" + (i + 1).ToString() + ")" + "." + ext),
                            //文件URL
                            Url = videos[i]
                        };
                    }

                    //添加文件路径到List<>中
                    _filePath.Add(currentParameter.FilePath);
                    //下载文件
                    bool success;
                    //添加断点续传段
                    if (File.Exists(currentParameter.FilePath))
                    {
                        //取得文件长度
                        int len = int.Parse(new FileInfo(currentParameter.FilePath).Length.ToString());
                        //设置RangeStart属性
                        currentParameter.RangeStart = len;
                    }
                    //下载视频文件
                    success = Network.DownloadFile(currentParameter);
                    //未出现错误即用户手动停止
                    if (!success)
                    {
                        _status = DownloadStatus.已经停止;
                        delegates.Finish(new ParaFinish(this.TaskId, false));
                        return;
                    }
                }
            }
            catch (Exception ex)             //出现错误即下载失败
            {
                _status = DownloadStatus.出现错误;
                delegates.Error(new ParaError(this.TaskId, ex));
                return;
            }
            //下载成功完成
            _status = DownloadStatus.载完成;
            delegates.Finish(new ParaFinish(this.TaskId, true));
        }