Example #1
0
        public List <RemoteFileRef> GetLocalFileDatabase()
        {
            List <RemoteFileRef> list = new List <RemoteFileRef>();

            foreach (MNBookHeader book in Books)
            {
                RemoteFileRef bookFile = new RemoteFileRef();
                bookFile.Text     = book.BookTitle;
                bookFile.FileName = Path.GetFileName(book.FilePath);
                bookFile.LastTime = book.LastTimeSave;
                bookFile.Selected = true;
                bookFile.Local    = true;

                foreach (MNBookLanguage lang in book.Languages)
                {
                    RemoteFileRef langw = new RemoteFileRef();
                    langw.Local    = true;
                    langw.Selected = true;
                    langw.Text     = lang.LanguageName;
                    langw.LastTime = lang.LastTimeSave;
                    langw.FileName = Path.GetFileName(lang.FilePath);
                    bookFile.Subs.Add(langw);
                }

                list.Add(bookFile);
            }

            return(list);
        }
Example #2
0
        public static List <RemoteFileRef> StringToDB(string str)
        {
            List <RemoteFileRef> list = new List <RemoteFileRef>();

            RemoteFileRef currBook = null;
            RemoteFileRef currLang = null;

            foreach (string s in str.Split('\n', '\r'))
            {
                if (s.StartsWith("BOOK:"))
                {
                    currBook = new RemoteFileRef();
                    list.Add(currBook);
                    currBook.Text = s.Substring(5);
                }
                else if (s.StartsWith("LANG:"))
                {
                    currLang = new RemoteFileRef();
                    if (currBook.Subs == null)
                    {
                        currBook.Subs = new List <RemoteFileRef>();
                    }
                    currBook.Subs.Add(currLang);
                    currLang.Text = s.Substring(5);
                }
                else if (s.StartsWith("BOOKFILE:"))
                {
                    if (currBook != null)
                    {
                        currBook.FileName = s.Substring(9);
                    }
                }
                else if (s.StartsWith("LANGFILE:"))
                {
                    if (currLang != null)
                    {
                        currLang.FileName = s.Substring(9);
                    }
                }
                else if (s.StartsWith("BOOKTIME:"))
                {
                    if (currBook != null)
                    {
                        currBook.LastTime = s.Substring(9);
                    }
                }
                else if (s.StartsWith("LANGTIME:"))
                {
                    if (currLang != null)
                    {
                        currLang.LastTime = s.Substring(9);
                    }
                }
            }

            return(list);
        }
Example #3
0
        /// <summary>
        /// Assumptions: GetCurrentBookDatabase and SetRemoteDatabase
        /// were called prior to this method
        /// </summary>
        /// <returns></returns>
        public bool CalculateDatabaseStatus()
        {
            if (RemoteDatabase == null)
            {
                return(false);
            }


            List <RemoteFileRef> remoteDB = RemoteDatabase;
            List <RemoteFileRef> localDB  = new List <RemoteFileRef>();

            if (Books.Count == 0 && LastDirectory != null)
            {
                GetCurrentBookDatabase(LastDirectory);
            }
            localDB = GetLocalFileDatabase();

            foreach (RemoteFileRef rf in remoteDB)
            {
                rf.Selected = false;
                rf.Local    = false;

                RemoteFileRef local = FindRef(localDB, rf.Text);
                if (local != null)
                {
                    if (!local.LastTime.Equals(rf.LastTime))
                    {
                        local.NewVersionAvailable = true;
                    }

                    foreach (RemoteFileRef rlang in rf.Subs)
                    {
                        RemoteFileRef localLang = FindRef(local.Subs, rlang.Text);
                        if (localLang != null)
                        {
                            if (!localLang.LastTime.Equals(rlang.LastTime))
                            {
                                localLang.NewVersionAvailable = true;
                            }
                            rlang.Text = null;
                        }
                        else
                        {
                            rlang.Selected = false;
                            rlang.Local    = false;
                            local.Subs.Add(rlang);
                        }
                    }

                    rf.Text = null;
                }
                else
                {
                    localDB.Add(rf);
                    foreach (RemoteFileRef rlang in rf.Subs)
                    {
                        rlang.Selected = false;
                        rlang.Local    = false;
                    }
                }
            }

            DatabaseStatus = localDB;
            return(true);
        }