Skip to content

[Windows] Fix "Show log file in folder" once and for all #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2022
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
5 changes: 3 additions & 2 deletions electron/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ interface createLogFileReturn {
export function createNewLogFileAndClearOldOnces(): createLogFileReturn {
const date = new Date()
const logDir = app.getPath('logs')
const fmtDate = date.toISOString().replace(':', '_')
const fmtDate = date.toISOString().replaceAll(':', '_')
const newLogFile = join(logDir, `heroic-${fmtDate}.log`)
try {
openSync(newLogFile, 'w')
Expand All @@ -174,14 +174,15 @@ export function createNewLogFileAndClearOldOnces(): createLogFileReturn {
)
}

// Clean out logs that are more than a month old
try {
const logs = readdirSync(logDir)
logs.forEach((log) => {
if (log.includes('heroic-')) {
const dateString = log
.replace('heroic-', '')
.replace('.log', '')
.replace('_', ':')
.replaceAll('_', ':')
const logDate = new Date(dateString)
if (
logDate.getFullYear() < date.getFullYear() ||
Expand Down
7 changes: 1 addition & 6 deletions electron/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
heroicConfigPath,
heroicGamesConfigPath,
icon,
isWindows,
legendary
} from './constants'
import { logError, logInfo, LogPrefix, logWarning } from './logger/logger'
Expand Down Expand Up @@ -328,11 +327,7 @@ function resetHeroic() {
function showItemInFolder(item: string) {
if (existsSync(item)) {
try {
if (isWindows) {
execAsync(`explorer /Select,"${item}"`)
} else {
shell.showItemInFolder(item)
}
shell.showItemInFolder(item)
} catch (error) {
logError(
`Failed to show item in folder with: ${error}`,
Expand Down