Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on open itemOpened
- process(itemOpened)
- end open
- process(choose file)
- to process(aFile)
- set core to {"countrygamer_core", "countrygamer_countrygamer_core"}
- set wean to {"weepingangels", "countrygamer_weepingangelsmod"}
- set tele to {"tele", "countrygamer_tele"}
- set pvz to {"pvz", "countrygamer_pvz"}
- --display dialog filePath
- set colonPath to aFile as text
- set pathNames to split(colonPath, ":")
- set fullFileName to end of pathNames
- set nameArray to split(fullFileName, ".jar")
- set fileName to the beginning of nameArray
- set fileExt to end of nameArray
- set colonPath to "Macintosh HD:"
- set finderPath to "/"
- set lib_colon to "Macintosh HD:"
- set pathToScriptBuild to "/"
- set ignoreFolders to {"build", "libs"}
- set pathNames to pathNames's (items 2 thru -2)
- repeat with str in pathNames
- set colonPath to (colonPath & str & ":")
- set finderPath to (finderPath & str & "/")
- if ignoreFolders does not contain str then
- set pathToScriptBuild to (pathToScriptBuild & str & "/")
- end if
- end repeat
- -- Read build file, if exists
- set mcversion to "0.0.0"
- set core_version to "0.0.0"
- set tele_version to "0.0.0"
- set angel_version to "0.0.0"
- set pvz_version to "0.0.0"
- set typeList to {}
- try
- set file_txt to readFile(pathToScriptBuild & "custom_build.txt")
- set txtLines to split(file_txt, linefeed as text)
- repeat with txt in txtLines
- set type_and_version to split(txt, "=")
- set type to the beginning of type_and_version
- set tVersion to the end of type_and_version
- if type is equal to "mc" then
- set mcversion to tVersion
- end if
- if type is equal to "core" then
- set core_version to tVersion
- end if
- if type is equal to "tele" then
- set tele_version to tVersion
- end if
- if type is equal to "angel" then
- set angel_version to tVersion
- end if
- if type is equal to "pvz" then
- set pvz_version to tVersion
- end if
- if type is not equal to "mc" then
- copy type to the end of typeList
- end if
- end repeat
- end try
- set ignoreStr to end of pathNames
- repeat with str in pathNames
- if str is not equal to ignoreStr then
- set lib_colon to lib_colon & str & ":"
- end if
- end repeat
- set main_folder_colon to colonPath & fileName & ":"
- set main_folder_finder to finderPath & fileName & "/"
- set java_src_colon to main_folder_colon & "com:countrygamer:"
- set java_src_finder to main_folder_finder & "com/countrygamer/"
- set assets_colon to main_folder_colon & "assets:"
- set assets_finder to main_folder_finder & "assets/"
- try
- tell application "Finder" to delete folder (main_folder_colon)
- end try
- tell application "Archive Utility" to open aFile
- set java_folder_list to {"com", "countrygamer"}
- tell application "Finder"
- try
- delete folder (lib_colon & "Core:")
- delete folder (lib_colon & "WeepingAngel:")
- delete folder (lib_colon & "Tele:")
- delete folder (lib_colon & "PvZ:")
- end try
- -- Create folder "modid" at lib_colon folder
- try
- make new folder at (lib_colon) with properties {name:"Core"}
- make new folder at (lib_colon) with properties {name:"WeepingAngel"}
- make new folder at (lib_colon) with properties {name:"Tele"}
- make new folder at (lib_colon) with properties {name:"PvZ"}
- end try
- end tell
- -- Create src folders and assets folder in "modid" folder
- createFolders(lib_colon & "Core:", java_folder_list)
- createFolders(lib_colon & "WeepingAngel:", java_folder_list)
- createFolders(lib_colon & "Tele:", java_folder_list)
- createFolders(lib_colon & "PvZ:", java_folder_list)
- tell application "Finder"
- try
- make new folder at (lib_colon & "Core:") with properties {name:"assets"}
- make new folder at (lib_colon & "WeepingAngel:") with properties {name:"assets"}
- make new folder at (lib_colon & "Tele:") with properties {name:"assets"}
- make new folder at (lib_colon & "PvZ:") with properties {name:"assets"}
- end try
- end tell
- -- Repeat with the folders in the main directory
- ---- Copy folders to new destinations depending on folder name
- -- SRC
- tell application "Finder"
- set items_in_folder to folders of folder ((java_src_colon as alias))
- end tell
- repeat with item_in_folder in items_in_folder
- --display dialog (item_in_folder as text)
- set folderPath to item_in_folder as text
- set folderPathNames to split(folderPath, ":")
- set folderPathNames to folderPathNames's (items 1 thru -2)
- set folderName to the end of folderPathNames
- set typeFolderName to ""
- if (core) contains folderName then
- set typeFolderName to "Core"
- else if wean contains folderName then
- set typeFolderName to "WeepingAngel"
- else if tele contains folderName then
- set typeFolderName to "Tele"
- else if pvz contains folderName then
- set typeFolderName to "PvZ"
- end if
- duplicate item_in_folder to ((lib_colon & typeFolderName & ":com:countrygamer:") as alias)
- end repeat
- -- ASSETS
- tell application "Finder"
- set items_in_folder to folders of folder ((assets_colon as alias))
- end tell
- repeat with item_in_folder in items_in_folder
- --display dialog (item_in_folder as text)
- set folderPath to item_in_folder as text
- set folderPathNames to split(folderPath, ":")
- set folderPathNames to folderPathNames's (items 1 thru -2)
- set folderName to the end of folderPathNames
- set typeFolderName to ""
- if core contains folderName then
- set typeFolderName to "Core"
- else if wean contains folderName then
- set typeFolderName to "WeepingAngel"
- else if tele contains folderName then
- set typeFolderName to "Tele"
- else if pvz contains folderName then
- set typeFolderName to "PvZ"
- end if
- duplicate item_in_folder to ((lib_colon & typeFolderName & ":assets:") as alias)
- end repeat
- -- Zip the contents of each "modid" folder and put them in the lib_colon folder
- set core_zip_name to "CountryGamerCore_" & mcversion & "_" & core_version
- set angel_zip_name to "CountryGamerWeepingAngels_" & mcversion & "_" & angel_version
- set tele_zip_name to "CountryGamerTele_" & mcversion & "_" & tele_version
- set pvz_zip_name to "CountryGamerPvZ_" & mcversion & "_" & pvz_version
- tell application "Finder"
- try
- if typeList contains "core" then delete file (lib_colon & core_zip_name & ".zip")
- if typeList contains "angel" then delete file (lib_colon & angel_zip_name & ".zip")
- if typeList contains "tele" then delete file (lib_colon & tele_zip_name & ".zip")
- if typeList contains "pvz" then delete file (lib_colon & pvz_zip_name & ".zip")
- end try
- end tell
- if typeList contains "core" then
- set folderAlias to (lib_colon & "Core:") as alias
- zipper(folderAlias, core_zip_name)
- end if
- if typeList contains "angel" then
- set folderAlias to (lib_colon & "WeepingAngel:") as alias
- zipper(folderAlias, angel_zip_name)
- end if
- if typeList contains "tele" then
- set folderAlias to (lib_colon & "Tele:") as alias
- zipper(folderAlias, tele_zip_name)
- end if
- if typeList contains "pvz" then
- set folderAlias to (lib_colon & "PvZ:") as alias
- zipper(folderAlias, pvz_zip_name)
- end if
- -- Clean up folders
- tell application "Finder"
- try
- delete folder (lib_colon & fileName & ":")
- delete folder (lib_colon & "Core:")
- delete folder (lib_colon & "WeepingAngel:")
- delete folder (lib_colon & "Tele:")
- delete folder (lib_colon & "PvZ:")
- end try
- end tell
- tell application "Finder" to empty trash
- end process
- to split(someText, delimiter)
- set AppleScript's text item delimiters to delimiter
- set someText to someText's text items
- set AppleScript's text item delimiters to {""} --> restore delimiters to default value
- return someText
- end split
- on readFile(unixPath)
- set foo to (open for access (POSIX file unixPath))
- set txt to (read foo for (get eof foo) as «class utf8»)
- close access foo
- return txt
- end readFile
- to createFolders(theLocation, folderList)
- set loc to theLocation
- repeat with theFolder in folderList
- try
- --display dialog loc
- tell application "Finder" to make new folder at loc with properties {name:theFolder}
- set x to loc & theFolder & ":"
- set loc to x
- end try
- end repeat
- end createFolders
- to zipper(theItemAsAlias, newFileName)
- tell application "Finder"
- set itemPath to quoted form of POSIX path of theItemAsAlias
- --set fileName to name of theItemAsAlias
- set theFolder to POSIX path of (container of theItemAsAlias as alias)
- set zipFile to quoted form of (theFolder & newFileName & ".zip")
- do shell script "cd " & itemPath & ";zip -r " & zipFile & " *"
- end tell
- end zipper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement