Skip to content

Commit

Permalink
Merge pull request #27 from primetime43/dev
Browse files Browse the repository at this point in the history
3.2.0
  • Loading branch information
primetime43 authored Dec 1, 2024
2 parents 7285c10 + 7f1adec commit 99aa13d
Show file tree
Hide file tree
Showing 21 changed files with 1,315 additions and 949 deletions.
13 changes: 13 additions & 0 deletions X-IPTV/AppStrings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace X_IPTV
{
public static class AppStrings
{
public const string ChannelsHint = "Right-click on a channel to open it in the player or copy the URL. Hover over items for additional descriptions.";
}
}
2 changes: 1 addition & 1 deletion X-IPTV/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static class Instance

public static string selectedCategory { get; set; }

public static string programVersion = "v3.1.0";
public static string programVersion = "v3.2.0";

public static bool ShouldUpdateOnInterval(DateTime currentTime) // make this a settings config eventually maybe?
{
Expand Down
8 changes: 4 additions & 4 deletions X-IPTV/REST_Ops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ public static async Task<bool> UpdateChannelsEpgData(List<XtreamChannel> channel
// Does not store any past or future epg data
Instance.XtreamEPGDataList = epgDataList;

// Update the lastEpgDataLoadTime setting with the current date and time in ISO 8601 format
ConfigurationManager.UpdateSetting("lastEpgDataLoadTime", DateTime.UtcNow.ToString("o"));
// Update the lastEpgDataLoadTime setting with the local machine's current date and time in ISO 8601 format
ConfigurationManager.UpdateSetting("lastEpgDataLoadTime", DateTime.Now.ToString("o"));

return true;
}
Expand Down Expand Up @@ -648,8 +648,8 @@ public static async Task<bool> UpdateChannelsEpgData(List<M3UChannel> channels)
// Does not store any past or future epg data
Instance.M3UEPGDataList = epgDataList;

// Update the lastEpgDataLoadTime setting with the current date and time in ISO 8601 format
ConfigurationManager.UpdateSetting("lastEpgDataLoadTime", DateTime.UtcNow.ToString("o"));
// Update the lastEpgDataLoadTime setting with the local machine's current date and time in ISO 8601 format
ConfigurationManager.UpdateSetting("lastEpgDataLoadTime", DateTime.Now.ToString("o"));

return true;
}
Expand Down
81 changes: 59 additions & 22 deletions X-IPTV/Utilities/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace X_IPTV.Utilities
class ConfigurationManager
{
private static JObject _configuration;
private static string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppSettings.json");
private static readonly string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppSettings.json");

public static void InitializeConfiguration()
{
Expand All @@ -18,7 +18,9 @@ public static void InitializeConfiguration()
// If the configuration file doesn't exist, create it with default values
_configuration = new JObject
{
["vlcLocationPath"] = "",
["vlcLocationPath"] = "", // setting for vlc player
["genericPlayerPath"] = "", // setting for any generic
["defaultPlayer"] = "vlc", // Default player is VLC
["usersFolderPath"] = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XtreamUsers"),
["M3UFolderPath"] = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "M3U"),
["epgDataFolderPath"] = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EPGData"),
Expand All @@ -38,62 +40,98 @@ public static void InitializeConfiguration()
_configuration["usersFolderPath"] = string.IsNullOrEmpty(_configuration["usersFolderPath"]?.ToString()) ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XtreamUsers") : _configuration["usersFolderPath"];
_configuration["M3UFolderPath"] = string.IsNullOrEmpty(_configuration["M3UFolderPath"]?.ToString()) ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "M3U") : _configuration["M3UFolderPath"];
_configuration["epgDataFolderPath"] = string.IsNullOrEmpty(_configuration["epgDataFolderPath"]?.ToString()) ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EPGData") : _configuration["epgDataFolderPath"];
_configuration["defaultPlayer"] = string.IsNullOrEmpty(_configuration["defaultPlayer"]?.ToString()) ? "vlc" : _configuration["defaultPlayer"]; // Default to VLC if not set

// Save any updates back to the file
File.WriteAllText(filePath, _configuration.ToString());
}
}

public static string GetConfigFilePath()
{
return filePath;
}

public static string GetSetting(string key)
{
return _configuration?[key]?.ToString();
}

public static string GetDefaultPlayer()
{
return GetSetting("defaultPlayer") ?? "vlc"; // Default to VLC if the setting is missing
}

public static void SetDefaultPlayer(string player)
{
if (player != "vlc" && player != "generic")
{
throw new ArgumentException("Invalid player type. Only 'vlc' or 'generic' are allowed.");
}

UpdateSetting("defaultPlayer", player);
}

// Update a specific setting in the configuration
public static void UpdateSetting(string key, string value)
{
// Check if _configuration is null and initialize it if necessary
if (_configuration == null)
{
InitializeConfiguration();
}

// Update or add the setting
_configuration[key] = value;

// Save the updated configuration back to file
File.WriteAllText(filePath, _configuration.ToString());
}

// Dedicated method for VLC Path logic
public static string GetVLCPath()
// Generalized method for retrieving any player path
public static string GetPlayerPath(string key)
{
// Attempt to get the path from the configuration file
string vlcPath = GetSetting("vlcLocationPath");
string playerPath = GetSetting(key);

// Check if the path is not null/empty and if the file exists
if (!string.IsNullOrEmpty(vlcPath) && File.Exists(vlcPath))
if (!string.IsNullOrEmpty(playerPath) && File.Exists(playerPath))
{
return vlcPath;
return playerPath;
}
else
{
// Path is invalid or not set, find and update the path
vlcPath = FindVLCPath();
if (vlcPath != null)
// If looking for VLC path, try to find it in the registry
if (key == "vlcLocationPath")
{
// Update the configuration with the found path
_configuration["vlcLocationPath"] = vlcPath;
File.WriteAllText(filePath, _configuration.ToString());
playerPath = FindVLCPath();
if (!string.IsNullOrEmpty(playerPath))
{
UpdateSetting("vlcLocationPath", playerPath);
return playerPath;
}
}

// For any other or missing path, prompt user to select
playerPath = PromptUserForPlayerPath();
if (playerPath != null)
{
UpdateSetting(key, playerPath);
}
return vlcPath;
return playerPath;
}
}

// Prompts the user to select a video player path
private static string PromptUserForPlayerPath()
{
OpenFileDialog openFileDialog = new OpenFileDialog
{
Filter = "Executable Files (*.exe)|*.exe",
Title = "Select a Video Player"
};

return openFileDialog.ShowDialog() == true ? openFileDialog.FileName : null;
}

// Method to find VLC installation path
public static string FindVLCPath()
{
// Registry keys to check
string[] registryKeys = new string[]
{
@"SOFTWARE\VideoLAN\VLC",
Expand All @@ -114,8 +152,7 @@ public static string FindVLCPath()
}
}
}

return null; // VLC not found
}
}
}
}
Loading

0 comments on commit 99aa13d

Please sign in to comment.