Playlist Backup script = need help-check.

Discuss and share scripts and script files...
Post Reply
eil
Posts: 1617
Joined: 13 Jan 2011 19:44

Playlist Backup script = need help-check.

Post by eil »

I made a script for making backup of playlists. First it checks which were modified recently, then copies to backup folder, deletes the oldest bacups of same playlists, runs the player and additional app. The strange thing is: not so seldom it happens that XY hangs upon running this script, though only simple operations are happening.(out of 10 runs there almost sure will be 1 hang)
Eventually i thought maybe i'm unintentionally creating a problem with my code, so hope smbd can check it out.

Code: Select all

    $PotPlayerEXE = "<xydrive>\Progs\DAUM\PotPlayer1.7.21526.x64\PotPlayerMini64.exe";
	$src = gpc($PotPlayerEXE, "component", -3, 1)."\Playlist";
	$bkp = gpc($PotPlayerEXE, "component", -3, 1)."\Playlist_BACKUP";
	$limitCopy = "9";
	$limitTime = "24";
	$LinksEXE = gpc($PotPlayerEXE, "component", -3, 1)."\PotPlayerLinks.exe";   //add links app
	/*
	[LastBackup]
	date=2022-09-14 16:19
	*/
        
        if (gettokenindex("sandbox", "<curpath>", "\") != "0") {trayballoon "Sandbox location!", "DAUM Player Backup", 35, 1; end 1==1;}  //don't do false backup due to Sandbox location
	if (datediff(getkey("date", "LastBackup", self("file")), now("yyyy-mm-dd hh:nn"),"h") < $limitTime){
		trayballoon "Backup was done recently.", "DAUM Player Backup", 34, 1;
		runq $PotPlayerEXE;
		wait 10000;
		runq  $LinksEXE;
		end 1==1;
	}	
	
	$report = "";
	$src_list = quicksearch("/f", $src, |, "s");    // wildcar OR /f for all files OR blank for all items(folders included)
	foreach($src_item, $src_list, "|") {
		$src_item_file = getpathcomponent($src_item, "file"); //file name with ext
		$src_item_base = getpathcomponent($src_item, "base"); //"base", only name
		//$bkp_item_chk = quicksearch($src_item_file, $bkp);
		if(exists($bkp."\".$src_item_file)==0) {backupto $bkp, $src_item, 0, 1, 0,0,0,0,0;}  //1: preserve dates of copied file
		elseif(exists($bkp."\".$src_item_file)==1) {
			if(filesize($src_item) != filesize($bkp."\".$src_item_file)){  //size compare. reacts on data add/delete
				$get_date = report("{modified yyyy.mm.dd hh-nn}", $bkp."\".$src_item_file);
				renameitem('*='.$get_date, $bkp."\".$src_item_file, 1);  //1: Rename base (keep extension)
				backupto $bkp, $src_item, 0, 1, 0,0,0,0,0;  //1: preserve dates of copied file
				$report = $src_item_base.<crlf>.$report;
				setkey now("yyyy-mm-dd hh:nn"), "date", "LastBackup", self("file");
			
				$bkp_list = quicksearch($src_item_base."=", $bkp, |, "s");
				//echo $bkp_list;
				$bkp_list_num = gettokenindex($src_item_base."=", $bkp_list, |, "wc");  //2 (return count)   //w: Token has wildcards.   c: Return count the occurrences. 
				//echo $bkp_list_num;
				if($bkp_list_num > $limitCopy) {  
					$bkp_items= report("{Name}|", $bkp_list);
					$bkp_items_sort= formatlist($bkp_items, "s", |); 
					$bkp_old = gettoken($bkp_items_sort, 2, "|");  //name(with ext) of oldest item
					$bkp_old = $bkp."\".$bkp_old;
					//echo $bkp_old;
				delete 1, 0, $bkp_old;					
				}
			} 
		}		
	}
	if($report != ""){trayballoon "$report", "DAUM Player Backup", 33, 1;}

	runq $PotPlayerEXE;
	wait 10000;
	runq  $LinksEXE;
Win 7 SP1 x64 100% 1366x768

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Playlist Backup script = need help-check.

Post by highend »

Let it write log entries and the next time it hangs it will be easier to say in which part of the script it happened?
One of my scripts helped you out? Please donate via Paypal

eil
Posts: 1617
Joined: 13 Jan 2011 19:44

Re: Playlist Backup script = need help-check.

Post by eil »

highend wrote: 14 Sep 2022 15:43 Let it write log entries and the next time it hangs it will be easier to say in which part of the script it happened?
Never did this before - which log command should i use and where to put it?
Win 7 SP1 x64 100% 1366x768

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Playlist Backup script = need help-check.

Post by highend »

writefile()? One at the start to create a new file and then as often as you want in on_exist = a mode
One of my scripts helped you out? Please donate via Paypal

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Playlist Backup script = need help-check.

Post by jupe »

Haven't studied the script, but from a glance, you should try disabling SC setting backgroundfileops, at the start of the script.

eil
Posts: 1617
Joined: 13 Jan 2011 19:44

Re: Playlist Backup script = need help-check.

Post by eil »

jupe wrote: 14 Sep 2022 21:35 you should try disabling SC setting backgroundfileops, at the start of the script.
Testing for a week so far, seems to be this solves it.
Just hope i did it right with

Code: Select all

setting "backgroundedfileops", 0; 
... 
setting "backgroundedfileops", r;
so it switches off on start and restores back in the end.
Win 7 SP1 x64 100% 1366x768

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Playlist Backup script = need help-check.

Post by highend »

setting "backgroundedfileops", r;
Not necessary, it's autoreset
One of my scripts helped you out? Please donate via Paypal

eil
Posts: 1617
Joined: 13 Jan 2011 19:44

Re: Playlist Backup script = need help-check.

Post by eil »

highend wrote: 22 Sep 2022 19:18
setting "backgroundedfileops", r;
Not necessary, it's autoreset
It will sound dumb, but why/how? As i understand setting is meant to change XY settings via scripting, so why it may auto-reset?
Win 7 SP1 x64 100% 1366x768

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Playlist Backup script = need help-check.

Post by highend »

When the script ends
One of my scripts helped you out? Please donate via Paypal

Post Reply