Ejemplo n.º 1
0
 public static string GetThemeName(ThemeConfig theme)
 {
     return(theme.displayName ?? theme.themeId.Replace('_', ' '));
 }
Ejemplo n.º 2
0
 public static string GetThemeAuthor(ThemeConfig theme)
 {
     return(IsThemeDownloaded(theme) ? theme.imageCredits : "Apple");
 }
Ejemplo n.º 3
0
 public static bool IsTheme4Segment(ThemeConfig theme)
 {
     return(!JsonConfig.IsNullOrEmpty(theme.sunriseImageList) &&
            !JsonConfig.IsNullOrEmpty(theme.sunsetImageList));
 }
Ejemplo n.º 4
0
        public static bool IsThemeDownloaded(ThemeConfig theme)
        {
            string themePath = Path.Combine("themes", theme.themeId);

            return(Directory.Exists(themePath) && (Directory.GetFiles(themePath, theme.imageFilename).Length > 0));
        }
Ejemplo n.º 5
0
 private void DownloadNext(ThemeConfig theme)
 {
     this.Invoke(new Action(() => UpdatePercentage(0)));
     stopwatch.Start();
     wc.DownloadFileAsync(themeUris[themeUriIndex], themeZipDest, theme);
 }
        public ImageData GetImageData(SolarData data, ThemeConfig theme)
        {
            int[]     imageList;
            DateTime  segmentStart;
            DateTime  segmentEnd;
            ImageData imageData = new ImageData();

            if (!JsonConfig.settings.darkMode)
            {
                switch (GetCurrentDaySegment(data))
                {
                case DaySegment.AllDay:
                    imageList             = theme.dayImageList;
                    segmentStart          = DateTime.Today;
                    segmentEnd            = DateTime.Today.AddDays(1);
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.AllNight:
                    imageList             = theme.nightImageList;
                    segmentStart          = DateTime.Today;
                    segmentEnd            = DateTime.Today.AddDays(1);
                    imageData.daySegment4 = 3;
                    break;

                case DaySegment.Sunrise:
                    imageList             = theme.sunriseImageList;
                    segmentStart          = data.solarTimes[0];
                    segmentEnd            = data.solarTimes[1];
                    imageData.daySegment4 = 0;
                    break;

                case DaySegment.Day:
                    imageList             = theme.dayImageList;
                    segmentStart          = data.solarTimes[1];
                    segmentEnd            = data.solarTimes[2];
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.Sunset:
                    imageList             = theme.sunsetImageList;
                    segmentStart          = data.solarTimes[2];
                    segmentEnd            = data.solarTimes[3];
                    imageData.daySegment4 = 2;
                    break;

                default:
                    imageList             = theme.nightImageList;
                    imageData.daySegment4 = 3;

                    if (DateTime.Now < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    break;
                }
            }
            else
            {
                imageList = theme.nightImageList;

                BrightnessManager.ChangeBrightness(5);

                if (data.polarPeriod != PolarPeriod.None)
                {
                    segmentStart = DateTime.Today;
                    segmentEnd   = DateTime.Today.AddDays(1);
                }
                else if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (DateTime.Now < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            TimeSpan segmentLength = segmentEnd - segmentStart;
            TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

            int imageNumber = (int)((DateTime.Now - segmentStart).Ticks / timerLength.Ticks);

            imageData.imageId         = imageList[imageNumber];
            imageData.nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);

            return(imageData);
        }
Ejemplo n.º 7
0
        public Tuple <int, long> GetImageData(SolarData data, ThemeConfig theme, bool darkMode)
        {
            int[]    imageList;
            DateTime segmentStart;
            DateTime segmentEnd;

            if (!darkMode)
            {
                switch (GetCurrentDaySegment(data))
                {
                case DaySegment.Sunrise:
                    imageList    = theme.sunriseImageList;
                    segmentStart = data.solarTimes[0];
                    segmentEnd   = data.solarTimes[1];
                    break;

                case DaySegment.Day:
                    imageList    = theme.dayImageList;
                    segmentStart = data.solarTimes[1];
                    segmentEnd   = data.solarTimes[2];
                    break;

                case DaySegment.Sunset:
                    imageList    = theme.sunsetImageList;
                    segmentStart = data.solarTimes[2];
                    segmentEnd   = data.solarTimes[3];
                    break;

                default:
                    imageList = theme.nightImageList;

                    if (DateTime.Now < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    break;
                }
            }
            else
            {
                imageList = theme.nightImageList;

                if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (DateTime.Now < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            TimeSpan segmentLength = segmentEnd - segmentStart;
            TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

            int  imageNumber     = (int)((DateTime.Now - segmentStart).Ticks / timerLength.Ticks);
            long nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);

            return(new Tuple <int, long>(imageList[imageNumber], nextUpdateTicks));
        }
        public static ThemeConfig ImportTheme(string themePath, IntPtr dialogHandle)
        {
            string themeId    = Path.GetFileNameWithoutExtension(themePath);
            int    themeIndex = themeSettings.FindIndex(t => t.themeId == themeId);

            if (themeIndex != -1)
            {
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Paused);
                DialogResult result = MessageBox.Show(string.Format(_("The '{0}' theme is " +
                                                                      "already installed. Do you want to overwrite it?"), themeId), _("Question"),
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Normal);

                if (result != DialogResult.Yes)
                {
                    return(null);
                }
            }

            try
            {
                Directory.CreateDirectory(Path.Combine("themes", themeId));

                if (Path.GetExtension(themePath) != ".json")
                {
                    using (ZipArchive archive = ZipFile.OpenRead(themePath))
                    {
                        ZipArchiveEntry themeJson = archive.Entries.Single(
                            entry => Path.GetExtension(entry.Name) == ".json");
                        themeJson.ExtractToFile(Path.Combine("themes", themeId, "theme.json"),
                                                true);
                    }

                    ExtractTheme(themePath, themeId);
                }
                else
                {
                    File.Copy(themePath, Path.Combine("themes", themeId, "theme.json"), true);
                }

                ThemeConfig theme = JsonConfig.LoadTheme(themeId);

                if (themeIndex == -1)
                {
                    themeSettings.Add(theme);
                    themeSettings.Sort((t1, t2) => t1.themeId.CompareTo(t2.themeId));
                }
                else
                {
                    themeSettings[themeIndex] = theme;
                }

                return(theme);
            }
            catch (Exception e)
            {
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Error);
                MessageBox.Show(string.Format(_("Failed to import theme from {0}\n\n{1}"),
                                              themePath, e.Message), _("Error"), MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Normal);

                return(null);
            }
        }
        public SchedulerState GetImageData(SolarData data, ThemeConfig theme, DateTime current)
        {
            int[]          imageList = null;
            DateTime       segmentStart;
            DateTime       segmentEnd;
            SchedulerState imageData = new SchedulerState()
            {
                daySegment2 = isSunUp ? 0 : 1
            };

            // Use 4-segment mode if sunrise and sunset image lists are defined, and dark mode is not enabled
            if (theme != null && ThemeManager.IsTheme4Segment(theme) && !JsonConfig.settings.darkMode)
            {
                switch (GetDaySegment(data, current))
                {
                case DaySegment.AllDay:
                    imageList             = theme?.dayImageList;
                    segmentStart          = current.Date;
                    segmentEnd            = current.Date.AddDays(1);
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.AllNight:
                    imageList             = theme?.nightImageList;
                    segmentStart          = current.Date;
                    segmentEnd            = current.Date.AddDays(1);
                    imageData.daySegment4 = 3;
                    break;

                case DaySegment.Sunrise:
                    imageList             = theme?.sunriseImageList;
                    segmentStart          = data.solarTimes[0];
                    segmentEnd            = data.solarTimes[1];
                    imageData.daySegment4 = 0;
                    break;

                case DaySegment.Day:
                    imageList             = theme?.dayImageList;
                    segmentStart          = data.solarTimes[1];
                    segmentEnd            = data.solarTimes[2];
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.Sunset:
                    imageList             = theme?.sunsetImageList;
                    segmentStart          = data.solarTimes[2];
                    segmentEnd            = data.solarTimes[3];
                    imageData.daySegment4 = 2;
                    break;

                default:
                    imageList             = theme?.nightImageList;
                    imageData.daySegment4 = 3;

                    if (current < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(current.Date.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(current.Date.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    break;
                }
            }
            else
            {
                imageList = theme?.nightImageList;

                if (!JsonConfig.settings.darkMode && (isSunUp || data.polarPeriod == PolarPeriod.PolarDay))
                {
                    imageList = theme?.dayImageList;
                }

                if (data.polarPeriod != PolarPeriod.None)
                {
                    segmentStart = current.Date;
                    segmentEnd   = current.Date.AddDays(1);
                }
                else if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (current < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(current.Date.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(current.Date.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            if (imageList != null)
            {
                TimeSpan segmentLength = segmentEnd - segmentStart;
                TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

                int imageNumber = (int)((current.Ticks - segmentStart.Ticks) / timerLength.Ticks);
                imageData.imageId         = imageList[imageNumber];
                imageData.imageNumber     = imageNumber;
                imageData.nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);
            }

            return(imageData);
        }
Ejemplo n.º 10
0
        private static string GetCarouselItems(List <int> imageList, int activeImage, ThemeConfig theme)
        {
            List <string> lines = new List <string>();

            for (int i = 0; i < imageList.Count; i++)
            {
                if (i + 1 == activeImage)
                {
                    lines.Add("<div class=\"carousel-item active\">");
                }
                else
                {
                    lines.Add("<div class=\"carousel-item\">");
                }

                string imageFilename = theme.imageFilename.Replace("*", imageList[i].ToString());
                Uri    uri           = new Uri(Path.Combine(Environment.CurrentDirectory, "themes", theme.themeId, imageFilename));
                lines.Add(string.Format("  <img src=\"{0}\" alt=\"Image {1} of {2}\">", uri.AbsoluteUri, i + 1,
                                        imageList.Count));
                lines.Add("</div>");
            }

            return(string.Join(Environment.NewLine, lines));
        }
Ejemplo n.º 11
0
 public static void LaunchPreview(ThemeConfig theme, int activeImage)
 {
     System.Diagnostics.Process.Start(GeneratePreviewHtml(theme, activeImage));
 }