Example #1
0
 private static void UpdateInterval()
 {
     PreviousUpdate = DateTime.UtcNow;
     NextUpdate     = PreviousUpdate.AddMilliseconds(timeItems[Key]);
     Interval       = NextUpdate - PreviousUpdate;
     StorageService.SetDateInfo(NextUpdate, Key);
 }
Example #2
0
        public static void ExportLastTrack(LastTrack LastTrack)
        {
            // Check if it's time to remove what's on screen or not
            bool timesUp = (PreviousUpdate == DateTime.MinValue) ||
                           DateTime.Now > PreviousUpdate.Add(TimeSpan.FromSeconds((double)OnScreenDuration));
            bool rewriteArtistTitleFile = true;

            if (LastTrack != null)
            {
                // Export the artist
                // Check if the artist is the same than before, to limit unnecessary writes
                if (LastTrack.Artist != PreviousArtist)
                {
                    rewriteArtistTitleFile = true;
                    WriteMetaData(GetPath(ARTIST_FILENAME), LastTrack.Artist);
                    PreviousArtist    = LastTrack.Artist;
                    PreviousUpdate    = DateTime.Now;
                    IsArtistFileEmpty = false;
                }
                else
                {
                    if (!IsArtistFileEmpty && timesUp)
                    {
                        rewriteArtistTitleFile = true;
                        WriteMetaData(GetPath(ARTIST_FILENAME), string.Empty);
                        IsArtistFileEmpty = true;
                    }
                }
                // Export the title
                // Check if the title is the same than before, to limit unnecessary writes
                if (LastTrack.Title != PreviousTitle)
                {
                    rewriteArtistTitleFile = true;
                    WriteMetaData(GetPath(TITLE_FILENAME), LastTrack.Title);
                    PreviousTitle    = LastTrack.Title;
                    PreviousUpdate   = DateTime.Now;
                    IsTitleFileEmpty = false;
                }
                else
                {
                    if (!IsTitleFileEmpty && timesUp)
                    {
                        rewriteArtistTitleFile = true;
                        WriteMetaData(GetPath(TITLE_FILENAME), string.Empty);
                        IsTitleFileEmpty = true;
                    }
                }

                // Export the Artist+Title
                if (rewriteArtistTitleFile)
                {
                    WriteMetaData(GetPath(ARTIST_TITLE_FILENAME),
                                  string.Format("{0} {1} {2} {1}{1}{1} ", LastTrack.Artist, ProgramSettings.ArtistTitleSeparator, LastTrack.Title));
                    if (ProgramSettings.CustomExportEnabled)
                    {
                        WriteMetaData(GetPath(CUSTOM_FILENAME), CustomFormat(LastTrack));
                    }
                    if (ProgramSettings.JSONExportEnabled)
                    {
                        WriteMetaData(GetPath(JSON_FILENAME), JSONFormat(LastTrack));
                    }
                    PreviousUpdate = DateTime.Now;
                }
                else
                {
                    if (timesUp)
                    {
                        WriteMetaData(GetPath(ARTIST_TITLE_FILENAME), string.Empty);
                        WriteMetaData(GetPath(CUSTOM_FILENAME), string.Empty);
                    }
                }

                // Export the artwork
                // Check if the artwork is the same than before, to limit unnecessary writes

                string artworkFile;
                if (string.IsNullOrEmpty(LastTrack.ImagePath))
                {
                    // No artwork available, we take the default artwork if available
                    artworkFile = ProgramSettings.DefaultArtwork;
                }
                else
                {
                    // Artwork file is available
                    artworkFile = Rekordbox6Paths.AnalysisDataRootPath + LastTrack.ImagePath;
                }


                if (File.Exists(artworkFile))
                {
                    string artworkMD5 = GetMD5(artworkFile);
                    if (artworkMD5 != PreviousArtwork)
                    {
                        File.Copy(artworkFile,
                                  GetPath(ARTWORK_FILENAME),
                                  true);
                        PreviousArtwork    = artworkMD5;
                        PreviousUpdate     = DateTime.Now;
                        IsArtworkFileEmpty = false;
                    }
                    else
                    {
                        if (!IsArtworkFileEmpty && timesUp)
                        {
                            File.Delete(GetPath(ARTWORK_FILENAME));
                            IsArtworkFileEmpty = true;
                        }
                    }
                }
                else
                {
                    File.Delete(GetPath(ARTWORK_FILENAME));
                    PreviousUpdate     = DateTime.Now;
                    IsArtworkFileEmpty = true;
                }
            }
        }