Use glib to get portable mode dir

This should fix any non-ascii paths
Fix using negative index
merge from hexchat master