Пример #1
0
        /// <summary>
        /// load list of links from file
        /// </summary>
        /// <returns></returns>
        public static void LoadLinks()
        {
            if (AnySyncRunning)
            {
                throw new ApplicationException("Cannot load Links while any sync is running!");
            }

            _links = new List <SyncLink>();

            if (CreateDataFileIfNotExist())
            {
                return;
            }

            List <string> lines      = new List <string>(File.ReadAllLines(LinksDataFilePath));
            List <int>    errorLines = new List <int>();
            bool          linkSec    = false;

            int i = 0;

            foreach (string line in lines)
            {
                if (line.Trim().Equals("<links>"))
                {
                    linkSec = true;
                }
                else if (line.Trim().Equals("</links>"))
                {
                    break;
                }
                else if (linkSec)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    Link l = Link.CreateFromLine(line);
                    if (l != null)
                    {
                        SyncLink sl = new SyncLink(l);
                        _links.Add(sl);
                        LinkChanged(0, sl);
                    }
                    else
                    {
                        errorLines.Add(i);
                    }
                }

                i++;
            }
            if (errorLines.Count > 0)
            {
                MessageBox.Show($"Please check links.dat. \nBad format detected in lines: {string.Join(", ", errorLines)}",
                                @"Bad Format in Data-File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }