Individual User Saves Script

Discussion of plugin / script development for XBMC4Xbox
Post Reply
User avatar
Rocky5
Posts: 975
Joined: Sat Feb 08, 2014 5:27 am
Has thanked: 101 times
Been thanked: 257 times

Individual User Saves Script

Post by Rocky5 »

OK, I have made a script that will allow individual profiles to have there own save directories :D

Now this is my first python script & due to not knowing how to code in Python it was a fecking pain in the ass :twisted:

Once its finished, currently testing. I will upload it here, in file format & code format.

This scrip will be part of my XBMC for Kids mod. (Games section only)
the latter will include a no hassle setup, so kids can enjoy games with nice graphics (skin) & no way for them to arse up XBMC, or change stuff there not meant to.

Here is a preview.



Updated to match the version included in XBMC4Kids.

Profiles.py

Code: Select all

################################################################################
# Script by Rocky5
# Used to switch between save directories.
# Updated: 21 December 2014
#
# Now copied softmod saves if they exist to new created profiles.
# Now automatically sets the skin for the new profiles.
# Now has a nice progress bar.
# Refined the script
#
################################################################################

import os, xbmcgui, xbmc, shutil, glob, fileinput



# Removes XBMC save folder, so I can rename UDATA.
if os.path.isdir('E:\\UDATA\\0face008\\'):
	shutil.rmtree('E:\\UDATA\\0face008\\')
else:
    print 'Already Removed'

	
	
# Sets paths, for profiles names & locations.
Username = xbmc.getInfoLabel('system.profilename')
CurProfileName = (Username + '.profile')
CurProfilePath = ('E:\\UDATA\\' + CurProfileName)
CurProfilePathAlt = ('E:\\UDATA ' + Username)
CurProfile = ('E:\\UDATA ' + Username +b'\\' + CurProfileName)
GuiSettings = xbmc.translatePath( 'special://profile/guisettings.xml' )



# Check if UDATA exist if not make one.
if not os.path.exists("E:\\UDATA"):
	os.mkdir("E:\\UDATA")
	# These will be hidden on release
	# dialog = xbmcgui.Dialog()
	# dialog.ok("Notification","UDATA folder created.")
else:
	print "UDATA already exists"

# Check if Backup.profile exist if not make one.
if not os.path.exists("E:\\UDATA Backup"):
	profile = open("E:\UDATA\Backup.profile","w")
	profile.write(" ")
	profile.close()	
	# These will be hidden on release
	# dialog = xbmcgui.Dialog()
	# dialog.ok("Notification","Backup.profile created.")
else:
	print "UDATA Backup already exists"

	

# Get current profile from UDATA folder.
for TMPProfile in glob.glob(r'E:\UDATA\*.profile'):
	dirname, TMPProfile = os.path.split(TMPProfile)
	PrevProfileName, fileExtension = os.path.splitext(TMPProfile)
	PrevProfilePath = ('E:\\UDATA ' + PrevProfileName)
	PrevProfile = ('E:\\UDATA\\' + PrevProfileName + '.profile')

# Check to see if the current user is the current save folder.
if os.path.isfile(PrevProfile) and os.path.isfile(CurProfilePath):
	print ""
	# These will be hidden on release
	# dialog = xbmcgui.Dialog()
	# dialog.ok("Notification",Username + " saves already selected.")
	
	
# If user created folder rename to UDATA, if not then create folder.
elif os.path.isfile(CurProfile) and os.path.isfile(PrevProfile):
	os.rename('E:\\UDATA' , PrevProfilePath)
	os.rename(CurProfilePathAlt , 'E:\\UDATA')
	# These will be hidden on release
	# dialog = xbmcgui.Dialog()
	# dialog.ok("Notification","Changing to " + Username + " saves.")


# Checks for the presence of the user UDATA folder & if not present creates it.
elif not os.path.isfile(CurProfile):
	pDialog = xbmcgui.DialogProgress()
	ret = pDialog.create('Copying Saves', 'Please wait.')
	os.mkdir("E:\\UDATA " + Username)
	profile = open(CurProfile,"w")
	profile.write(" ")
	profile.close()
	os.rename('E:\\UDATA' , PrevProfilePath)
	os.rename(CurProfilePathAlt , 'E:\\UDATA')
	
	# Copy over the Softmod saves if they exist.
	if os.path.exists("E:\\UDATA Backup\\4541000d"):
		pDialog.update(20, 'Copying 007 Save.')
		shutil.copytree("E:\\UDATA Backup\\4541000d", "E:\\UDATA\\4541000d")
	else:
		print "Already copied 007 save folder"
	if os.path.exists("E:\\UDATA Backup\\4d530017"):
		pDialog.update(40, 'Copying Mechassault Save.')
		shutil.copytree("E:\\UDATA Backup\\4d530017", "E:\\UDATA\\4d530017")
	else:
		print "Already copied Mechassault save folder"
	if os.path.exists("E:\\UDATA Backup\\5553000c"):
		pDialog.update(60, 'Copying Splinter cell Save.')
		shutil.copytree("E:\\UDATA Backup\\5553000c", "E:\\UDATA\\5553000c")
	else:
		print "Already copied Splinter cell save folder"
	if os.path.exists("E:\\UDATA Backup\\21585554"):
		pDialog.update(80, 'Copying Softmod files Save.')
		shutil.copytree("E:\\UDATA Backup\\21585554", "E:\\UDATA\\21585554")
	else:
		print "Already copied Softmod save folder"


	# Check to see if current user is Master & if not edit current skin & log out.
	if Username == "DVD2Xbox":
		print "Master Profile"
	else:
		pDialog.update(100, 'Done.')
		pDialog.close()
		dialog = xbmcgui.Dialog()
		dialog.ok("Thats everything setup","I will need to log you out "+Username+".","So I can complete the process.","Hope you understand.")
		
		# Change user skin.
		for line in fileinput.input(GuiSettings, inplace=True):
			print(line.replace("<skin>Master Profile</skin>", "<skin>Profile skin</skin>"))
			xbmc.executebuiltin("System.LogOff()")
else:
	print ""
startup.xml

Code: Select all

<window id="2999">
	<defaultcontrol always="true">10</defaultcontrol>
	<allowoverlay>no</allowoverlay>
	<controls>
		<control type="button" id="10">
			<posx>-5000</posx>
			<description>Trigger</description>
			<onfocus>Special://xbmc/scripts/Profiles.py</onfocus>
			<onfocus>ReplaceWindow(Home)</onfocus>
		</control>
	</controls>
</window>
Download Xbox Softmodding Tool & Extras Disc
XBMC4Kids Mod


Xbox Gamertag = Connxtion
PSN ID = JCRocky5
Post Reply