Thoughts on using $HOME for __PATH__system-write-data__

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
Post Reply
Lexxy Fox
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sun Jan 01, 2017 3:32 am
Contact:

Thoughts on using $HOME for __PATH__system-write-data__

Post by Lexxy Fox »

Hello,

On Linux it seems that Factorio uses

Code: Select all

getpwuid(getuid())->pw_dir + "/.factorio"
as the value of "__PATH__system-write-data__", which is a little inconvenient. Could the value of "__PATH__system-write-data__" be changed to "$HOME/.factorio" or maybe something else instead? Changing it to "$HOME/.factorio" shouldn't break too much, since for most people I'm sure that $HOME is generally equal to getpwuid(getuid())->pw_dir anyway.

Typically, XDG's paths are preferable, but failing that I believe using $HOME is much preferred over getpwuid() since it's easier to work with.

What I'd like:
1. For Factorio to instead use XDG paths as "__PATH__system-write-data__" values: $XDG_CONFIG_HOME/factorio.ini for Factorio's config file, $XDG_CACHE_HOME/factorio for the "temp" folder and "crop-cache.dat", and $XDG_DATA_HOME/factorio for probably everything else? I think that's how it goes, I dunno. Somebody should spend more than 5 seconds thinking about good XDG compliance.
2. Don't like that? It is a big change, so here's a compromise: Use "$HOME/.factorio", falling back to getpwuid(getuid())->pw_dir if $HOME isn't defined.

P.S. Thank you so much for using /usr/share/factorio as "__PATH__system-read-data__"

quyxkh
Smart Inserter
Smart Inserter
Posts: 1029
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Thoughts on using $HOME for __PATH__system-write-data__

Post by quyxkh »

You can point Factorio at anything you want in the config file, which you can call out from the command line. So to completely customize your setup you can make a ~/bin/Factorio (or wherever) options-processing frontend. My standard getopts seed template is

Code: Select all

while getopts x-: opt; do case $opt in 
	x) set -x ;;
	*) echo $opt $OPTIND $OPTARG ;;
esac; done; shift $((_=--OPTIND,OPTIND=1,_))
echo $OPTIND
and you can add anything to it, mine has slowly grown by accretion until it starts with this works-for-me monstrosity, with my default config file generator at the end of the quote here and factorio invoked with `$prefix/bin/factorio -c $config "${gameopts[@]}" "$@"`:

Code: Select all

#!/bin/bash
# Factorio options-and-setup frontend, overrides native -s, -m
# to mean server and multiplayer-client startup
# makes default startup reload last local game, pass a bare `-` to not
graphics=${graphics-normal} gameopts=() annotopts=() loadgame=--load-game loadlatest=1; for f; do case $f in
	- | --create | --load-game | --benchmark* | --mp-connect \
		| --start-server* | --map2scenario | --scenario2map )
	loadlatest=0 ;;
esac; done
findgame() {
	# set any prefix/version/server path before asking for a game pattern
	local saves=${prefix-$HOME/.factorio$version$serverpath}/saves
	local IFS=$'\n'
	[[ ! -r $1 && $1 != */* ]] \
		&& set -- "`find $saves -iname "*$1*" -exec ls -t {} + |sed q`"
	[[ -r $1 ]] && loadlatest=0
	printf %s $1
}
while getopts :h?-:G:g:snp:qCc:xvVNmM:b:0123456789.t: opt; do case $opt in
	#*) [[ $- == *x* ]] && echo $OPTIND'*'$opt'*'$OPTARG ;;&
	[gmbnhC:]) loadlatest=0 ;;&  # want no-arg `-` to be `-n` equiv
	V) mods=vanilla ;;
	M) mods=$OPTARG ;;
	g) gameopts+=($loadgame "`findgame "$OPTARG"`") ;;
	m) gameopts+=(--mp-connect $(jq -r '."latest-multiplayer-connections"[0].address' ${prefix-$HOME/.factorio}/player-data.json)) ;;
	s) serverpath=/server loadgame=--start-server ;;
	b) gameopts+=(--benchmark "`findgame "$OPTARG"`" --disable-audio) graphics=very-low;;
	t) gameopts+=(--benchmark-ticks "$OPTARG") loadgame=--benchmark ;;
	G) graphics=$OPTARG ;;
	p) prefix=$OPTARG ;;
	x) set -x ;;
	c) config=$OPTARG ;;
	C) updateopt=d@0 loadlatest=0 ;;
	N) annotate= ;;
	q) annotopts+=(quiet=1) ;;
	# overcomplicated version-picker option parsing:
	[0-3]) version=${version-/}$opt ;;
	[4-9]) version=${version-/1}$opt ;;
	.) version=${version-/17}$opt;;
	# `--` stops frontend option processing, all long options passed along to
	# game engine, `--help` is processed by both frontend and engine
	"-") ((--OPTIND)); [[ $OPTARG = help  ]] && sed /^$/Q "$0"; break ;;
	# and `-h` is passed along too because that works well enough
	h|\?) sed '/^$/Q' "$0"; gameopts+=(-h) ;;
	v) gameopts+=(-v)
esac; done; shift $((OPTIND-1))

prefix=${prefix-$HOME/.factorio}$version$serverpath
[[ -n $mods ]] && {
	[[ $mods = */* ]] || mods=$prefix/mods.$mods
	gameopts+=(--mod-directory "$mods")
	mkdir -p "$mods"
}

(( loadlatest && $# == 1 )) && [[ $1 != -* ]] && {
	gameopts+=($loadgame "`findgame "$1"`")
	loadlatest=0
}

config=${config-$prefix/config/config.ini}

[[ -r $config ]] || cat <<-EOD >$config
	[path]
	read-data=__PATH__executable__/../../data
	write-data=$prefix
	[other]
	$([[ ${version:-/16} < /16 ]] || echo non-blocking-saving=true)
	EOD


Post Reply

Return to “Technical Help”