Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ permissions:
jobs:
auto-approve:
runs-on: ubuntu-latest
if: >-
github.event.pull_request.user.login == 'ccombe' ||
github.event.pull_request.user.login == 'github-actions[bot]'
if: github.event.pull_request.user.login == 'ccombe'
steps:
- name: Auto-approve
env:
Expand Down
153 changes: 15 additions & 138 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@ on:
push:
branches: [master, main]
workflow_dispatch:
inputs:
bump_type:
description: "Manual bump type override (patch, minor, major, or auto)"
required: false
default: "auto"
type: choice
options:
- auto
- patch
- minor
- major

permissions:
contents: write
pull-requests: write

jobs:
release:
name: Semantic Release & Publish
name: Build & Publish Release
runs-on: windows-latest
steps:
- name: Checkout code
Expand All @@ -31,136 +19,25 @@ jobs:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Calculate Semantic Version
# Version lives in src/version.h (bumped in a normal PR). A release
# happens whenever that version has no matching tag yet.
- name: Decide whether to release
id: semver
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MANUAL_BUMP: ${{ github.event.inputs.bump_type }}
run: |
git fetch --tags --force
$tags = git tag -l --sort=-v:refname "v*"
$latestTag = if ($tags) { ($tags -split "`r?`n")[0].Trim() } else { $null }

if (-not $latestTag) {
Write-Host "No existing release tags found. Setting initial baseline version."
$content = Get-Content src/version.h -Raw
$m = [regex]::Match($content, 'FIP_VERSION\s+"([^"]+)"')
$base = if ($m.Success) { $m.Groups[1].Value } else { "1.4.0" }
$parts = $base.Split('.')
while ($parts.Count -lt 3) { $parts += '0' }
$newVersion = ($parts[0..2] -join '.')
$newTag = "v$newVersion"
$range = "HEAD"
} else {
Write-Host "Latest release tag found: $latestTag"
$range = "$latestTag..HEAD"
# Ignore automated "chore(release)" bump commits; they do not drive new releases
# (prevents an infinite patch-bump loop after a release lands).
$subjects = @(git log $range --pretty=format:"%s")
$meaningful = @($subjects | Where-Object { $_ -notmatch "^chore\(release\)" })
if (-not $meaningful) {
Write-Host "No new meaningful commits since $latestTag. Skipping release."
Write-Output "should_release=false" >> $env:GITHUB_OUTPUT
exit 0
}
$commitText = ($meaningful -join "`n").Trim()

$raw = $latestTag.TrimStart('v')
$parts = $raw.Split('.')
while ($parts.Count -lt 3) { $parts += '0' }
[int]$major = $parts[0]
[int]$minor = $parts[1]
[int]$patch = $parts[2]

$bump = if ($env:MANUAL_BUMP -and $env:MANUAL_BUMP -ne 'auto') { $env:MANUAL_BUMP } else { $null }
if (-not $bump) {
if ($commitText -match "(?m)^[a-zA-Z]+(\([^\)]+\))?!:" -or $commitText -match "BREAKING CHANGE") {
$bump = "major"
} elseif ($commitText -match "(?m)^feat(\([^\)]+\))?:") {
$bump = "minor"
} else {
$bump = "patch"
}
}

Write-Host "Determined bump type: $bump"
if ($bump -eq "major") {
$major++
$minor = 0
$patch = 0
} elseif ($bump -eq "minor") {
$minor++
$patch = 0
} else {
$patch++
}

$newVersion = "$major.$minor.$patch"
$newTag = "v$newVersion"
}

Write-Output "should_release=true" >> $env:GITHUB_OUTPUT
Write-Output "version=$newVersion" >> $env:GITHUB_OUTPUT
Write-Output "tag=$newTag" >> $env:GITHUB_OUTPUT
Write-Output "range=$range" >> $env:GITHUB_OUTPUT
Write-Host "Calculated next release: $newVersion (tag: $newTag)"

- name: Update version.h and CHANGELOG.md
if: steps.semver.outputs.should_release == 'true'
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ver = "${{ steps.semver.outputs.version }}"
$today = (Get-Date).ToString("yyyy-MM-dd")

# 1. Update src/version.h
$vh = Get-Content src/version.h -Raw
$vhUpdated = [regex]::Replace($vh, 'FIP_VERSION\s+"[^"]+"', "FIP_VERSION `"$ver`"")
$vhUpdated | Out-File src/version.h -Encoding utf8

# 2. Update CHANGELOG.md
$cl = Get-Content CHANGELOG.md -Raw
$shortVer = $ver -replace '\.0$', ''
$hasHeader = ($cl -match [regex]::Escape("## [$ver]")) -or ($cl -match [regex]::Escape("## [$shortVer]"))
if (-not $hasHeader) {
$range = "${{ steps.semver.outputs.range }}"
$commitLines = @(git log $range --pretty=format:"- %s (%h)")
$commitBody = if ($commitLines.Count -gt 0) { $commitLines -join "`n" } else { "- Maintenance and updates." }

$newEntry = "## [Unreleased]`n`n## [$ver] - $today`n`n### Changes`n$commitBody"
if ($cl -match "(?ms)^## \[Unreleased\].*?(?=^## \[|\z)") {
$unreleasedContent = [regex]::Match($cl, "(?ms)^## \[Unreleased\]\s*(.*?)(?=^## \[|\z)").Groups[1].Value.Trim()
if ($unreleasedContent -ne "") {
$newEntry = "## [Unreleased]`n`n## [$ver] - $today`n`n$unreleasedContent"
}
$cl = [regex]::Replace($cl, "(?ms)^## \[Unreleased\].*?(?=^## \[|\z)", "$newEntry`n`n")
} else {
$cl = "## [Unreleased]`n`n## [$ver] - $today`n`n$commitBody`n`n" + $cl
}
$cl | Out-File CHANGELOG.md -Encoding utf8
}

# 3. Commit the bump on a release branch and open an auto-merge PR -
# master requires pull requests (branch protection), so a direct push is rejected.
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add src/version.h CHANGELOG.md
git diff-index --quiet HEAD
if ($LASTEXITCODE -ne 0) {
npx prettier --write CHANGELOG.md
git add src/version.h CHANGELOG.md
$branch = "release/bump-version$($ver -replace '\.', '-')"
git checkout -b $branch
git commit -m "chore(release): bump version to $ver"
# force: a previous attempt may have left the branch behind
git push origin $branch --force
$prUrl = gh pr create --title "chore(release): bump version to $ver" --body "Automated version bump for v$ver. Auto-merges once checks pass."
gh pr merge $prUrl --auto --squash
Write-Host "Opened auto-merge PR for version bump: $prUrl"
$m = [regex]::Match($vh, 'FIP_VERSION\s+"([^"]+)"')
$ver = if ($m.Success) { $m.Groups[1].Value } else { "0.0.0" }
git fetch --tags --force
$exists = git rev-parse -q --verify "refs/tags/v$ver" 2>$null
if ($LASTEXITCODE -eq 0 -and $exists) {
Write-Host "Tag v$ver already exists. Skipping release."
Write-Output "should_release=false" >> $env:GITHUB_OUTPUT
} else {
Write-Host "No file changes needed for version bump."
Write-Host "Will release v$ver"
Write-Output "should_release=true" >> $env:GITHUB_OUTPUT
Write-Output "version=$ver" >> $env:GITHUB_OUTPUT
Write-Output "tag=v$ver" >> $env:GITHUB_OUTPUT
}

- name: Setup MSBuild
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Versions match `FIP_VERSION` in `src/version.h`.

## [Unreleased]

## [1.8.1] - 2026-10-18

### Fixed

- Find Dead/Empty Directories now scans the whole watched tree: roots are the deepest shared folder per volume, so empty folders that sit beside album folders are found too. Folders containing subfolders are no longer misreported as dead.
- The Properties dialog now shows the "Playlists" group reliably: playlist lookups hop to the main thread when foobar enumerates properties on a worker thread.

## [1.8.0] - 2026-10-17

### Changes
Expand Down
58 changes: 49 additions & 9 deletions scripts/check_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,55 @@
import argparse

def strip_comments_and_strings(code: str) -> str:
# Remove single line comments
code = re.sub(r"//.*", "", code)
# Remove multi-line comments
code = re.sub(r"/\*.*?\*/", "", code, flags=re.DOTALL)
# Remove string literals
code = re.sub(r"\"(?:\\.|[^\"\\])*\"", "\"\"", code)
# Remove char literals
code = re.sub(r"\'(?:\\.|[^\'\\])*\'", "''", code)
return code
# Single-pass state machine: comment stripping must not run before string
# handling, or a "://" inside a string literal is mistaken for a comment
# start and desynchronizes quote/brace pairing for the whole file.
out = []
i = 0
n = len(code)
state = 0 # 0: code, 1: line comment, 2: block comment, 3: string, 4: char
while i < n:
c = code[i]
nxt = code[i + 1] if i + 1 < n else ""
if state == 0:
if c == "/" and nxt == "/":
state = 1
i += 2
elif c == "/" and nxt == "*":
state = 2
i += 2
elif c == '"':
state = 3
out.append('"')
i += 1
elif c == "'":
state = 4
out.append("'")
i += 1
else:
out.append(c)
i += 1
elif state == 1: # line comment: keep the newline
if c == "\n":
state = 0
out.append("\n")
i += 1
elif state == 2: # block comment
if c == "*" and nxt == "/":
state = 0
i += 2
else:
i += 1
else: # string (3) or char (4): keep quotes, drop escapes whole
if c == "\\":
i += 2
elif (state == 3 and c == '"') or (state == 4 and c == "'"):
state = 0
out.append(c)
i += 1
else:
i += 1
return "".join(out)

def analyze_functions(filepath: str, is_unit_tested: bool = False):
with open(filepath, "r", encoding="utf-8", errors="ignore") as f:
Expand Down
76 changes: 76 additions & 0 deletions src/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "logic.h"

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

Expand Down Expand Up @@ -39,6 +40,81 @@ bool has_invalid_tag_chars(const char *field) {
return false;
}

namespace {

// Lowercase everything so volume/prefix matching is case-insensitive.
std::string normalized_dir(std::string s) {
for (auto & c : s) {
if (c == '/')
c = '\\';
else
c = static_cast<char>(::tolower(static_cast<unsigned char>(c)));
}
return s;
}

// Append the \\-separated path components of s[start..] to out.
void split_components(std::vector<std::string> & out, const std::string & s, size_t start) {
size_t i = start;
while (i < s.size()) {
size_t next = s.find('\\', i);
if (next == std::string::npos)
next = s.size();
if (i < next) // ignore empty segments (e.g. doubleslash)
out.push_back(s.substr(i, next - i));
i = next + 1;
}
}

// True if every directory in the volume shares comps[i] == part.
bool all_share_component(const std::vector<std::vector<std::string>> & comps, size_t i, const std::string & part) {
for (const auto & c : comps) {
if (i >= c.size() || c[i] != part)
return false;
}
return true;
}

} // namespace

// Deepest shared ancestor (per drive volume) of the given directory paths:
// the top folder to scan so empty sibling folders in the watched tree are found.
// Returns one root per volume that actually holds library directories.
std::vector<std::string> common_scan_roots(const std::unordered_set<std::string> & dirPaths) {
// volume ("g:\") -> (component lists, one original-case dir to cut the root from)
struct vol {
std::vector<std::vector<std::string>> comps;
const std::string *sample = nullptr;
};
std::unordered_map<std::string, vol> byVolume;
for (const auto & raw : dirPaths) {
if (raw.find("://") != std::string::npos) // network / stream path
continue;
const std::string norm = normalized_dir(raw);
const size_t colon = norm.find(":\\");
if (colon == std::string::npos) // not a file path
continue;
const std::string volume = norm.substr(0, colon + 2);
auto & v = byVolume[volume];
v.comps.push_back({});
split_components(v.comps.back(), norm, volume.size());
v.sample = &raw;
}

std::vector<std::string> roots;
roots.reserve(byVolume.size());
for (auto & [volume, v] : byVolume) {
size_t rootLen = volume.size(); // original-case root cut from the sample dir
for (size_t i = 0; i < v.comps[0].size(); ++i) {
if (!all_share_component(v.comps, i, v.comps[0][i]))
break;
rootLen += v.comps[0][i].size() + 1; // component + separator
}
roots.push_back(v.sample->substr(0, rootLen));
}
return roots;
}

bool record_track_playlist_match(const std::string & key, const std::string & playlistName,
const std::unordered_map<std::string, size_t> & indexOf,
std::vector<track_report> & reports) {
Expand Down
4 changes: 4 additions & 0 deletions src/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ enum class dir_status {

// Classifies a list of filenames (not full paths) in a directory.
dir_status classify_directory(const std::vector<std::string> & filenames);

// Deepest shared ancestor (per drive volume) of the given directory paths - the
// top folders to scan so empty sibling folders in the watched tree are found.
std::vector<std::string> common_scan_roots(const std::unordered_set<std::string> & dirPaths);
12 changes: 8 additions & 4 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@

class playlist_property_provider : public track_property_provider_v5 {
public:
// v5 property properties are enumerated off the main thread in fb2k v2;
// playlist APIs are main-thread only, so hop there synchronously.
void enumerate_properties_v5(trackListRef items, track_property_provider_v5_info_source &,
track_property_callback_v2 & cb, abort_callback &) override {
if (!core_api::is_main_thread())
return; // playlist APIs are main-thread only
track_property_callback_v2 & cb, abort_callback & abort) override {
if (!cb.is_group_wanted("Playlists"))
return;
metadb_handle_list sel;
for (size_t i = 0; i < items.get_size(); ++i)
sel.add_item(items[i]);
std::vector<track_report> reports;
find_playlists_for(sel, reports);
if (core_api::is_main_thread()) {
find_playlists_for(sel, reports);
} else {
fb2k::inMainThreadSynchronous([&] { find_playlists_for(sel, reports); }, abort);
}
for (const auto & r : reports) {
pfc::string_formatter count;
count << r.lists.size();
Expand Down
Loading
Loading