示例#1
0
        /// <summary>
        /// Handler for refresh button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void Refresh_Click(object sender, RoutedEventArgs args)
        {
            if (this.BeginTransaction())
            {
                return;
            }

            try
            {
                if (Directory.Exists(Settings.OnlineDatabaseFolder))
                {
                    string[] files = Directory.GetFiles(Settings.OnlineDatabaseFolder);
                    foreach (string file in files)
                    {
                        File.Delete(file);
                    }

                    Directory.Delete(Settings.OnlineDatabaseFolder);
                }

                if (File.Exists(Settings.OnlineDatabaseLog))
                {
                    File.Delete(Settings.OnlineDatabaseLog);
                }

                if (File.Exists(Settings.OnlineDatabaseZip))
                {
                    File.Delete(Settings.OnlineDatabaseZip);
                }

                if (File.Exists(Settings.FileList_Online))
                {
                    File.Delete(Settings.FileList_Online);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Log("Could not cleanup old stuff, will try to rebuild anyway.", ex);
            }

            this.activeList = null;
            this.UpdateFileList();

            this.EndTransaction();
        }
示例#2
0
        /// <summary>
        /// Parse the online repository and create athe online file list
        /// </summary>
        private void BuildOnlineFile()
        {
            if (File.Exists(Settings.FileList_Online))
            {
                return;
            }

            WallpaperList tmpList = null;

            try
            {
                tmpList = new WallpaperList(Settings.FileList_Online, false);

                string[] files = Directory.GetFiles(Settings.OnlineDatabaseFolder);
                foreach (string file in files)
                {
                    using (Stream fileStream = File.Open(file, FileMode.Open))
                    {
                        using (StreamReader fileReader = new StreamReader(fileStream))
                        {
                            while (true)
                            {
                                string line = fileReader.ReadLine();
                                if (line == null)
                                {
                                    break;
                                }

                                if (line.StartsWith("#"))
                                {
                                    continue;
                                }

                                string filePath            = null;
                                int    firstDelimiterIndex = line.IndexOf('|');
                                if (firstDelimiterIndex != -1)
                                {
                                    filePath = line.Substring(0, firstDelimiterIndex);
                                }

                                if (string.IsNullOrEmpty(filePath))
                                {
                                    continue;
                                }

                                string dimensions           = null;
                                int    secondDelimiterIndex = line.IndexOf('^', firstDelimiterIndex);
                                if (secondDelimiterIndex != -1)
                                {
                                    dimensions = line.Substring(firstDelimiterIndex + 1, secondDelimiterIndex - firstDelimiterIndex - 1);
                                }

                                string thumbnail = null;
                                if ((secondDelimiterIndex < line.Length))
                                {
                                    thumbnail = line.Substring(secondDelimiterIndex + 1);
                                }

                                if (string.IsNullOrEmpty(thumbnail))
                                {
                                    thumbnail = filePath;
                                }

                                tmpList.AddFile(filePath, thumbnail, dimensions);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (tmpList != null)
                {
                    tmpList.SaveToFile();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Create and load the file list based on the settings
        /// </summary>
        public void UpdateFileList()
        {
            if (Settings.Instance.FileListIndex == 0)
            {
                // if none loaded or different from active one, reload
                if (this.activeList == null ||
                    this.activeList.Path != Settings.FileList_Online)
                {
                    try
                    {
                        OnlineRepository online = new OnlineRepository();
                        if (online.SyncToLocal())
                        {
                            if (File.Exists(Settings.FileList_Online))
                            {
                                File.Delete(Settings.FileList_Online);
                            }
                        }

                        this.BuildOnlineFile();
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.Log("Unable to sync with online repository, the cached list will be used.", ex);
                    }

                    WallpaperList list = null;
                    try
                    {
                        list = new WallpaperList(Settings.FileList_Online, false);
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Log("There was an error loading the online file list, loading an empty list.", e);

                        if (File.Exists(Settings.FileList_Online))
                        {
                            File.Delete(Settings.FileList_Online);
                        }

                        list = new WallpaperList(Settings.FileList_Online, false);
                    }

                    this.activeList = list;
                }

                c_copyPath.Visibility   = Visibility.Collapsed;
                c_openFolder.Visibility = Visibility.Collapsed;
                c_deleteFile.Visibility = Visibility.Collapsed;
            }
            else
            {
                // if none loaded or different from active one, reload
                if (this.activeList == null ||
                    this.activeList.Path != Settings.FileList_Local)
                {
                    WallpaperList list = null;
                    try
                    {
                        list = new WallpaperList(Settings.FileList_Local, true);
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Log("There was an error loading the local file list, loading an empty list.", e);

                        if (File.Exists(Settings.FileList_Local))
                        {
                            File.Delete(Settings.FileList_Local);
                        }

                        list = new WallpaperList(Settings.FileList_Local, true);
                    }

                    this.activeList = list;
                }

                c_copyPath.Visibility   = Visibility.Visible;
                c_openFolder.Visibility = Visibility.Visible;
                c_deleteFile.Visibility = Visibility.Visible;
            }

            c_filelist.ItemsSource = this.activeList.List;
            if (this.activeList.Count > 0)
            {
                c_imagenext.IsEnabled = true;
            }
            else
            {
                c_imagenext.IsEnabled = false;
            }
        }