示例#1
0
        public static List <ConversationListObject> GetConvsFromIndividualFiles()
        {
            byte[] data = null;
            List <ConversationListObject> convList = null;

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.DirectoryExists(CONVERSATIONS_DIRECTORY))
                {
                    return(null);
                }
                string[] files = store.GetFileNames(CONVERSATIONS_DIRECTORY + "\\*");
                if (files == null || files.Length == 0)
                {
                    return(null);
                }
                convList = new List <ConversationListObject>(files.Length);
                foreach (string fileName in files)
                {
                    if (fileName == "Convs" || fileName == "Convs_bkp" || fileName == "_Convs")
                    {
                        continue;
                    }
                    using (var file = store.OpenFile(CONVERSATIONS_DIRECTORY + "\\" + fileName, FileMode.Open, FileAccess.Read))
                    {
                        using (var reader = new BinaryReader(file))
                        {
                            ConversationListObject co = new ConversationListObject();
                            co.ReadVer_Latest(reader); // we know we have to read from latest file system
                            if (IsValidConv(co))
                            {
                                convList.Add(co);
                            }
                        }
                    }
                }
            }
            convList.Sort();
            return(convList);
        }
示例#2
0
        /// <summary>
        /// this function will automatically read which read function version should be used to read file
        /// </summary>
        /// <returns></returns>

        public static List <ConversationListObject> getAllConvs()
        {
            List <ConversationListObject> convList = null;

            // when reading a file , nobody should write it
            lock (readWriteLock)
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!store.DirectoryExists(CONVERSATIONS_DIRECTORY))
                    {
                        return(null);
                    }
                    string fname;
                    if (store.FileExists(CONVERSATIONS_DIRECTORY + "\\" + "Convs"))
                    {
                        fname = CONVERSATIONS_DIRECTORY + "\\" + "Convs";
                    }
                    else if (store.FileExists(CONVERSATIONS_DIRECTORY + "\\" + "Convs_bkp"))
                    {
                        fname = CONVERSATIONS_DIRECTORY + "\\" + "Convs_bkp";
                    }
                    else
                    {
                        return(null);
                    }

                    using (var file = store.OpenFile(fname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        using (var reader = new BinaryReader(file))
                        {
                            int count = 0;
                            try
                            {
                                count = reader.ReadInt32();
                            }
                            catch
                            {
                            }
                            if (count > 0)
                            {
                                bool isLessThanEqualTo_1500 = false;
                                if (Utils.compareVersion(App.CURRENT_VERSION, "1.5.0.0") != 1) // current_ver <= 1.5.0.0
                                {
                                    isLessThanEqualTo_1500 = true;
                                }

                                convList = new List <ConversationListObject>(count);
                                for (int i = 0; i < count; i++)
                                {
                                    ConversationListObject item = new ConversationListObject();
                                    try
                                    {
                                        if (isLessThanEqualTo_1500)
                                        {
                                            item.ReadVer_1_4_0_0(reader);
                                        }
                                        else
                                        {
                                            item.ReadVer_Latest(reader);
                                        }
                                    }
                                    catch
                                    {
                                        item = null;
                                    }
                                    if (IsValidConv(item))
                                    {
                                        convList.Add(item);
                                    }
                                }
                                convList.Sort();
                            }
                            reader.Close();
                        }
                        try
                        {
                            file.Close();
                            file.Dispose();
                        }
                        catch { }
                    }
                    store.Dispose();
                }
                return(convList);
            }
        }