home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2007 February / maximum-cd-2007-02.iso / main.dxr / Internal_107_filecopylogic.ls < prev    next >
Encoding:
Text File  |  2006-07-19  |  8.6 KB  |  287 lines

  1. global fd, macfix, fileCount, fileArray, successFiles, path, database
  2.  
  3. on installfont fontfile, fontName
  4.   put "installFont(" & fontfile & ", " & fontName & ")"
  5.   if baFontInstalled(fontfile, EMPTY) then
  6.     displayMessage("Font already installed", "The font you are trying to install is already installed on your machine.")
  7.   else
  8.     if fd = ":" then
  9.       displayMessage("Error", "We're sorry, the font install feature is only available on the PC version of this disc.  Please use the download feature and install manually.")
  10.     else
  11.       err = baInstallFont(fontfile, fontName)
  12.       if err <> 0 then
  13.         case err of
  14.           1:
  15.             displayMessage("Error", "A font with that name is already installed on your computer.")
  16.           2:
  17.             displayMessage("Error", "The font file was not found.")
  18.           3:
  19.             displayMessage("Error", "Error copying font file.  You may not have permission to install fonts on this machine.")
  20.           4:
  21.             displayMessage("Error", "Windows couldn't install the font.")
  22.           5:
  23.             displayMessage("Error", "The font file has an invalid file name.")
  24.         end case
  25.       else
  26.         displayMessage("Success!", "Font successfully installed.")
  27.       end if
  28.     end if
  29.   end if
  30. end
  31.  
  32. on installAllFonts
  33.   put "installAllFonts()"
  34.   if fd = ":" then
  35.     displayMessage("Error", "We're sorry, the font install feature is only available on the PC version of this disc.  Please use the download feature and install manually.")
  36.   else
  37.     err = 0
  38.     if displayYesNo("Install All Fonts?", "Are you sure you want this disc to install all of its fonts onto your system?  The process may take a couple of minutes, please be patient.  If you would like to continue, click 'Yes,' otherwise, click 'No.'") then
  39.       repeat with i = 1 to count(database)
  40.         entry = database[i]
  41.         if baFontInstalled(the pathname & "assets" & fd & "data" & fd & "fonts" & fd & entry.fontfile, EMPTY) then
  42.           nothing()
  43.           next repeat
  44.         end if
  45.         e = baInstallFont(the pathname & "assets" & fd & "data" & fd & "fonts" & fd & entry.fontfile, entry.fontName)
  46.         if e > 1 then
  47.           err = err + e
  48.         end if
  49.       end repeat
  50.       if err > 0 then
  51.         displayMessage("Error", "All fonts could not be successfully installed.  Some fonts may be installed, while others may not.")
  52.       else
  53.         displayMessage("Success!", "Fonts successfully installed.")
  54.       end if
  55.     end if
  56.   end if
  57. end
  58.  
  59. on copyFolder folderN
  60.   put "copyFolder(" & folderN & ")"
  61.   path = promptUserFolderPath(stripPath(convertFileDelimiter(folderN, "/", fd), fd))
  62.   if path = 0 then
  63.     fileCopyError(path, EMPTY)
  64.   else
  65.     errCount = 0
  66.     successFiles = 0
  67.     file = convertFileDelimiter(folderN, "/", fd)
  68.     if fd = "\" then
  69.       baCreateFolder(path & fd & stripPath(file, fd))
  70.     end if
  71.     if fd = ":" then
  72.       if ((the environment).osVersion contains "10") or ((the environment).osVersion contains "11") then
  73.         Ok = baXCopy(file, path, "*", "Always", 1)
  74.       else
  75.         Ok = baXCopy(file, path & fd & stripPath(file, fd), "*", "Always", 1)
  76.       end if
  77.     else
  78.       Ok = baXCopy(file, path & fd & stripPath(file, fd), "*", "Always", 1)
  79.     end if
  80.     if Ok <> 0 then
  81.       displayError("I was unable to copy the files successfully.")
  82.     else
  83.       if fd = ":" then
  84.         fList = baFileList(path, "*.*")
  85.         baSetFilePermissions(path & ":", "u", "rwx")
  86.         baSetFilePermissions(path & ":", "g", "rwx")
  87.         baSetFilePermissions(path & ":", "o", "rwx")
  88.         repeat with i = 1 to fList.count
  89.           thisFile = path & ":" & fList[i]
  90.           baSetFilePermissions(thisFile, "u", "rwx")
  91.           baSetFilePermissions(thisFile, "g", "rwx")
  92.           baSetFilePermissions(thisFile, "o", "rwx")
  93.         end repeat
  94.       end if
  95.       displayMessage("Success!", "The files were copied successfully.")
  96.     end if
  97.   end if
  98. end
  99.  
  100. on copyFile fileN
  101.   put " PATH - " & stripPath(convertFileDelimiter(fileN, "/", fd), fd)
  102.   path = promptUserPath(stripPath(convertFileDelimiter(fileN, "/", fd), fd))
  103.   if (fileN contains ".jpg") and not (path contains ".jpg") then
  104.     path = path & ".jpg"
  105.   else
  106.     if (fileN contains ".pdf") and not (path contains ".pdf") then
  107.       path = path & ".pdf"
  108.     end if
  109.   end if
  110.   if path = 0 then
  111.     fileCopyError(path, EMPTY)
  112.   else
  113.     errCount = 0
  114.     successFiles = 0
  115.     file = convertFileDelimiter(fileN, "/", fd)
  116.     put "source file = " & file
  117.     put "dest path = " & path
  118.     if fd = ":" then
  119.       if ((the environment).osVersion contains "10") or ((the environment).osVersion contains "11") then
  120.         Ok = baCopyFile(file, path, "Always")
  121.       else
  122.         Ok = baCopyFile(file, path & fd & stripPath(file, fd), "Always")
  123.       end if
  124.     else
  125.       Ok = baCopyFile(file, path, "Always")
  126.     end if
  127.     if Ok <> 0 then
  128.       fileCopyError(path, translateBaCopyFileError(Ok))
  129.     else
  130.       success()
  131.     end if
  132.   end if
  133. end
  134.  
  135. on fileCopyError p, err
  136.   if err <> EMPTY then
  137.     displayError("I was unable to copy all the files successfully." && err)
  138.   else
  139.     displayError("I was unable to copy all the files successfully.")
  140.   end if
  141. end
  142.  
  143. on promptUserFolderPath fileN
  144.   if fd = ":" then
  145.     if ((the environment).osVersion contains "10") or ((the environment).osVersion contains "11") then
  146.       return fileSaveAs(fileN, "Choose a folder to save the folder, and click 'Save'.")
  147.     else
  148.       p = fileSaveAs(fileN, "Choose a folder to save the folder, and click 'Save'.")
  149.       if p <> 0 then
  150.         return stripEnd(p, fd)
  151.       else
  152.         return 0
  153.       end if
  154.     end if
  155.   else
  156.     p = fileSaveAs(fileN, "Choose a folder to save the folder, and click 'Save'.")
  157.     if p <> 0 then
  158.       return stripEnd(p, fd)
  159.     else
  160.       return 0
  161.     end if
  162.   end if
  163. end
  164.  
  165. on promptUserPath fileN
  166.   if fd = ":" then
  167.     if ((the environment).osVersion contains "10") or ((the environment).osVersion contains "11") then
  168.       return fileSaveAs(fileN, "Choose a folder to save the file(s), and click 'Save'.")
  169.     else
  170.       p = fileSaveAs(fileN, "Choose a folder to save the file(s), and click 'Save'.")
  171.     end if
  172.   else
  173.     p = fileSaveAs(fileN, "Choose a location and folder name, and click 'Save'.")
  174.     if p <> 0 then
  175.       return p
  176.     else
  177.       return 0
  178.     end if
  179.   end if
  180. end
  181.  
  182. on success me
  183.   displayMessage("File copied", "File copied successfully.")
  184. end
  185.  
  186. on displayError Msg
  187.   alertObj = new(xtra("MUI"))
  188.   alertInitList = [#buttons: #Ok, #title: "Error", #message: Msg, #movable: 1]
  189.   if objectp(alertObj) then
  190.     result = alert(alertObj, alertInitList)
  191.     case result of
  192.       1:
  193.         return 1
  194.     end case
  195.   end if
  196.   alertObj = VOID
  197. end
  198.  
  199. on displayMessage title, Msg
  200.   alertObj = new(xtra("MUI"))
  201.   alertInitList = [#buttons: #Ok, #title: title, #message: Msg, #movable: 1]
  202.   if objectp(alertObj) then
  203.     result = alert(alertObj, alertInitList)
  204.     case result of
  205.       1:
  206.         return 1
  207.     end case
  208.   end if
  209.   alertObj = VOID
  210. end
  211.  
  212. on displayYesNo title, Msg
  213.   alertObj = new(xtra("MUI"))
  214.   alertInitList = [#buttons: #YesNo, #title: title, #message: Msg, #movable: 1]
  215.   if objectp(alertObj) then
  216.     result = alert(alertObj, alertInitList)
  217.     case result of
  218.       1:
  219.         return 1
  220.       otherwise:
  221.         return 0
  222.     end case
  223.   end if
  224. end
  225.  
  226. on translateBaCopyFileError errNum
  227.   case errNum of
  228.     0:
  229.       return "Copy successful"
  230.     1:
  231.       return "Invalid Source file name"
  232.     2:
  233.       return "Invalid Destination file name"
  234.     3:
  235.       return "Error reading the Source file"
  236.     4:
  237.       return "Error writing the Destination file"
  238.     5:
  239.       return "Couldn't create directory for Destination file"
  240.     6:
  241.       return "Destination file already exists"
  242.     7:
  243.       return "Destination file is newer than the Source file"
  244.   end case
  245.   return EMPTY
  246. end
  247.  
  248. on fileSaveAs fileString, prompt
  249.   put "fileSaveAs(" & fileString & ", " & prompt & ")"
  250.   aMuiObj = new(xtra("MUI"))
  251.   result = FileSave(aMuiObj, fileString, prompt)
  252.   put "returned: " & result
  253.   if result <> fileString then
  254.     return result
  255.   else
  256.     return 0
  257.   end if
  258.   aMuiObj = VOID
  259. end
  260.  
  261. on convertFileDelimiter fileString, oldDelimiter, newDelimiter
  262.   numchars = fileString.char.count
  263.   repeat with i = 1 to numchars
  264.     if fileString.char[i] = oldDelimiter then
  265.       put newDelimiter into fileString.char[i]
  266.     end if
  267.   end repeat
  268.   return fileString
  269. end
  270.  
  271. on stripPath fileString, delimiter
  272.   x = the itemDelimiter
  273.   the itemDelimiter = delimiter
  274.   fileN = item the number of items in fileString of fileString
  275.   the itemDelimiter = x
  276.   return fileN
  277. end
  278.  
  279. on stripEnd fileString, delimiter
  280.   x = the itemDelimiter
  281.   the itemDelimiter = delimiter
  282.   fileN = fileString
  283.   delete item the number of items in fileN of fileN
  284.   the itemDelimiter = x
  285.   return fileN
  286. end
  287.