Help with Callback and File.Copy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Mattyc_92
    Forum Member
    • Aug 2004
    • 2

    Help with Callback and File.Copy

    Hi, I have downloaded the Trial version (again) of AutoPlay Media Studio and am thinking about buying it.

    After many hours looking at this forum and using the Help files, I have finally started to create a script which I am having trouble with the "Callback" function for the "File.Copy" option.

    Here is the coding I am using:

    Code:
    continue = Dialog.Message("", "This will detect what \"Operating System\" you are running and load up the correct Media Player\r\nClick OK to continue", MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1)
    if continue == IDOK then
    	os_name = System.GetOSName()
    	My_Docs = Shell.GetFolder(SHF_MYDOCUMENTS)
    	
    	function CopyFileDialog(Filename, nPercent)
    		StatusDlg.SetTitle("Copying File...")
    		StatusDlg.SetMessage("Please Wait....\r\nNow copying \"Windows Media Player\" onto your system\r\nYou can cancel at anytime")
    		StatusDlg.SetStatusText("Copied "..nPercent.."%")
    		StatusDlg.SetMeterRange(0, 100)
    		StatusDlg.SetMeterPos(nPercent)
    		StatusDlg.ShowCancelButton(true, "Cancel Copying")
    		local cancelled = StatusDlg.IsCancelled()
    		if cancelled then
    			StatusDlg.Hide()
    			return false
    		else
    			return true
    		end
    	end
    	
    	if os_name == "Windows XP" then
    		copy_installation = Dialog.Message("", "Do you wish to copy the Installation for \"Windows Media Player 10\" into a folder of your choosing", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1)
    		if copy_installation == IDYES then
    			copy_file = Dialog.FileBrowse(false, "Select Location...", My_Docs, "Installation File (*.exe)|*.exe|", "Media Player 10", "", false, false)
    			if copy_file[1] ~= "CANCEL" then
    				if copy_file ~= "" or copy_file ~= " " then
    					StatusDlg.Show()
    					File.Copy("mp10setup.exe", copy_file[1], false, false, true, true, CopyFileDialog)
    					StatusDlg.Hide()
    					Dialog.Message("Copy Completed", "File copied successfully")
    					run_file = Dialog.Message("Run Installation?", "Do you wish to run the installation now?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1)
    					if run_file == IDYES then
    						File.Run(copy_file[1], "", "", SW_SHOWNORMAL, false)
    					end
    				end
    			end
    		else
    			File.Run("mp10setup.exe", "", "", SW_SHOWNORMAL, false)
    		end
    	else
    		copy_installation = Dialog.Message("", "Do you wish to copy the Installation for \"Windows Media Player 9\" into a folder of your choosing", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1)
    		if copy_installation == IDYES then
    			copy_file = Dialog.FileBrowse(false, "Select Location...", My_Docs, "Installation File (*.exe)|*.exe|", "Media Player 9", "", false, false)
    			if copy_file[1] ~= "CANCEL" then
    				if copy_file ~= "" or copy_file ~= " " then
    					StatusDlg.Show()
    					File.Copy("MPSetup.exe", copy_file[1], false, false, true, true, CopyFileDialog)
    					StatusDlg.Hide()
    					Dialog.Message("Copy Completed", "File copied successfully")
    					run_file = Dialog.Message("Run Installation?", "Do you wish to run the installation now?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1)
    					if run_file == IDYES then
    						File.Run(copy_file[1], "", "", SW_SHOWNORMAL, false)
    					end
    				end
    			end
    		else
    			File.Run("MPSetup.exe", "", "", SW_SHOWNORMAL, false)
    		end
    	end
    end
    Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE)
    I have got the Callback function working (in a way). The only thing is that it wont display the process in either the "Progress Display" nor the Progress Bar...

    Can anyone help?
  • Mattyc_92
    Forum Member
    • Aug 2004
    • 2

    #2
    Ok, so I have "tinkered" with the code, and kind of got it working perfectly....

    I have changed the code to:

    Code:
    user = System.GetUserInfo()
    os_name = System.GetOSName()
    my_docs = Shell.GetFolder(SHF_MYDOCUMENTS)
    
    Dialog.TimedMessage("Please Wait......", "Please wait, now detecting your \"Operating System\" and launching the correct \"Media Player Installation\"\r\nThis may take up to 10 seconds.", 5000, MB_ICONINFORMATION)
    
    function ZipDialog(sfilename, nPercent)
    	StatusDlg.SetTitle("Copying File...")
    	StatusDlg.SetMessage("Now copying \""..version.."\" onto your system....\r\nYou may cancel this at any time...")
    	StatusDlg.SetStatusText(""..nPercent.."% Copied")
    	StatusDlg.SetMeterPos(nPercent)
    	StatusDlg.ShowCancelButton(true, "Abort Copy")
    	local bCancel = StatusDlg.IsCancelled()
    	if bCancel then
    		StatusDlg.Hide()
    		Dialog.Message("", "You have cancelled the proceedure")
    		File.Delete(""..location.."\\"..file_to_copy.."")
    		return false
    	else
    		return true
    	end
    end
    if user.IsAdmin then
    	if os_name == "Windows XP" then
    		version = "Microsoft Windows Media Player 10"
    		file_to_copy = "10.exe"
    		open = "media player_.exe"
    		Application.RunScriptFile("AutoPlay\\Scripts\\script.lua")
    	end
    	
    	if os_name == "Windows 98" or os_name == "Windows 2000" or os_name == "Windows ME" then
    		version = "Microsoft Windows Media Player 9"
    		file_to_copy = "9.exe"
    		open = "mediaplayer_.exe"
    		Application.RunScriptFile("AutoPlay\\Scripts\\script.lua")
    	end
    	
    	if not os_name == "Windows 98" or not os_name == "Windows 2000" or not os_name == "Windows ME" or not os_name == "Windows XP" then
    		Dialog.Message("Error", "Your \"Operating System\" (\""..os_name.."\") isn't compatiable with ANY of the versions of \"Microsoft Windows Media Player\" that are included on this disk.\r\nThis Menu will now close.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1)
    	end
    else
    	Dialog.Message("Permission Error", "You do not have \"Administrator\" rights....\r\nPlease logon as an \"Administrator\" and try again...", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1)
    end
    Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE)
    And the script it loads is:
    Code:
    error = 0
    	copy = Dialog.Message("Copy Installation?", "Your Operating System has been delected as \""..os_name.."\"\r\nDo you wish to copy the installation for \""..version.."\" into a folder of your choosing (on your system for future use without this disk)?\r\nClick \"Yes\" to copy the Installation, click \"No\" to just run the installation from the disk or click \"Cancel\" to close this Menu, and leave your System as it is.", MB_YESNOCANCEL, MB_ICONQUESTION, MB_DEFBUTTON1)
    	if copy == IDYES then
    		nLocation = Dialog.FolderBrowse("Select a Directory:", my_docs)
    		if nLocation ~= "CANCEL" then
    			file_name = Dialog.Input("File-Name...", "Please type in a NAME for the file e.g:\r\n\"Windows Media Player Installation\"", ""..version.."", MB_ICONINFORMATION)
    			if file_name ~= "" or file_name ~= " " or file_name ~= "CANCEL" then
    				StatusDlg.Show()
    				Zip.Extract("AutoPlay\\Docs\\install.zip", {file_to_copy}, nLocation, false, false, "avril", ZIP_OVERWRITE_NEVER, ZipDialog)
    				StatusDlg.Hide()
    				if not bCancel then
    					File.Rename(""..nLocation.."\\"..file_to_copy.."", ""..nLocation.."\\"..file_name..".exe")
    					error = Application.GetLastError()
    					if error ~= 0 then
    						Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONSTOP, MB_DEFBUTTON1)
    						File.Delete(""..nLocation.."\\10.exe", false, true, true, nil)
    						File.Delete(""..nLocation.."\\"..file_name..".exe", false, true, true, nil)
    					else
    						open_installation = Dialog.Message("Success", "File copied Successfully\r\nDo you wish to open the Installation now?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1)
    						if open_installation == IDYES then
    							File.Run(""..nLocation.."\\"..file_name..".exe", "", "", SW_SHOWNORMAL, false)
    						end
    					end
    				end
    			end
    		end
    	else
    		if copy == IDNO then
    			File.Run(open, "", "", SW_SHOWNORMAL, false)
    		else
    			if copy == IDCANCEL then
    				Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE)
    			end
    		end
    	end
    The coding is now working almost perfectly, now I have discovered that this type of callback function is for "Zip" commands.
    But what I am getting (the only problem with the code) is that if a User aborts, all I get is the Dialog message none stop. I have to ctrl+alt+del it to stop it. It is just in a loop, it will tell you you have cancelled, and tells you again, and again, and again.

    Can anyone help?

    Comment

    Working...
    X