Skip to content

Commit

Permalink
Add detection of custom Songs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jun 29, 2016
1 parent 92e4fc4 commit 1036c05
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions osu!StreamCompanion/Code/Misc/SettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace osu_StreamCompanion.Code.Misc
public sealed class SettingNames
{//main
public readonly ConfigEntry MainOsuDirectory = new ConfigEntry("MainOsuDirectory", "");
public readonly ConfigEntry SongsFolderLocation = new ConfigEntry("SongsFolderLocation", "Songs");
public readonly ConfigEntry LogLevel = new ConfigEntry("LogLevel", Core.DataTypes.LogLevel.Disabled.GetHashCode());
public readonly ConfigEntry StartHidden = new ConfigEntry("StartHidden", false);
public readonly ConfigEntry Console = new ConfigEntry("console", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class OsuFallbackDetector : IModule, ISettings
private readonly SettingNames _names = SettingNames.Instance;
//LastVersion = b20160403.6
private const string LAST_FALLBACK_VERSION = "b20160403.6";

private bool _isFallback;
private string _customBeatmapDirectoryLocation;
private Settings _settings;
public bool Started { get; set; }
public void Start(ILogger logger)
Expand All @@ -29,26 +30,35 @@ public void Start(ILogger logger)
logger.Log("WARNING: Could not get correct osu! config location. Tried: \"{0}\"", LogLevel.Basic, FilePath);
return;
}
bool isFallback = IsFallback(FilePath);
ReadSettings(FilePath);

_settings.Add(_names.OsuFallback.Name, isFallback);
if (isFallback)
_settings.Add(_names.OsuFallback.Name, _isFallback);
if (_isFallback)
logger.Log("Detected osu fallback version!", LogLevel.Basic);

_settings.Add(_names.SongsFolderLocation.Name, _customBeatmapDirectoryLocation);
if (_customBeatmapDirectoryLocation != _names.SongsFolderLocation.Default<string>())
logger.Log("Detected custom songs folder location \"{0}\"", LogLevel.Basic, _customBeatmapDirectoryLocation);
}

public void SetSettingsHandle(Settings settings)
{
_settings = settings;
}

private bool IsFallback(string configPath)
private void ReadSettings(string configPath)
{
foreach (var cfgLine in File.ReadLines(configPath))
{
if (cfgLine.StartsWith("BeatmapDirectory"))
{
var splitedLines = cfgLine.Split(new[] { '=' }, 2);
var songDirectory = splitedLines[1].Trim(' ');
_customBeatmapDirectoryLocation = songDirectory;
}
if (cfgLine.StartsWith("LastVersion") && cfgLine.Contains(LAST_FALLBACK_VERSION))
return true;
_isFallback = true;
}
return false;
}

private string GetConfigFilePath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ public void Start(ILogger logger)
{
Started = true;
_logger = logger;
var dir = _settings.Get<string>(_names.MainOsuDirectory);
if (dir != "")
var dir = _settings.Get<string>(_names.SongsFolderLocation);
if (dir == _names.SongsFolderLocation.Default<string>())
{

dir = _settings.Get<string>(_names.MainOsuDirectory);
dir = Path.Combine(dir, "Songs\\");
}

if (dir != "")
{
watcher = new FileSystemWatcher(dir, "*.osu");
watcher.Created += Watcher_FileCreated;
watcher.IncludeSubdirectories = true;
Expand All @@ -38,7 +42,7 @@ private void Watcher_FileCreated(object sender, FileSystemEventArgs e)
{
_logger.Log("Detected new beatmap in songs folder", LogLevel.Debug);
var beatmap = BeatmapHelpers.ReadBeatmap(e.FullPath);

_sqlite.StoreTempBeatmap(beatmap);
_logger.Log("Added new Temporary beatmap {0} - {1}", LogLevel.Debug, beatmap.ArtistRoman, beatmap.TitleRoman);
}
Expand Down

0 comments on commit 1036c05

Please sign in to comment.