home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / MacFormat 92 CD / Shareware Plus / Utilities / FolderSynchronizer 1.8.9 / FoldersSynchronizer / FoldersSynchronizer.9 / AllScripts_2_1SyncScripts.ls < prev    next >
Encoding:
Text File  |  2000-05-10  |  26.2 KB  |  757 lines

  1. on AllScripts_______________________
  2. end
  3.  
  4. on AskForSourceFolder
  5.   global gMultiAll, gSourceFolder, gDestFolder, gTopFolder, gSourceFolderList, gSourceFileList
  6.   if gMultiAll then
  7.     GoMulti()
  8.   else
  9.     if (gSourceFolder <> EMPTY) and (OSIsDirectory(gSourceFolder) = 1) then
  10.       dosSetCurrentFolder(ExtractParentFolder(gSourceFolder))
  11.     end if
  12.     set TempgSourceFolder to OSSelectFolder()
  13.     if TempgSourceFolder = 0 then
  14.       exit
  15.     end if
  16.     if TempgSourceFolder = gDestFolder then
  17.       AlertBox("You cannot choose the same Folder two times.")
  18.       exit
  19.     end if
  20.     set gTopFolder to TempgSourceFolder
  21.     set gSourceFolder to TempgSourceFolder
  22.     set gSourceFolderList to []
  23.     set gSourceFileList to []
  24.     put AccorciaNome(gSourceFolder) into field "fSourceFolder"
  25.     put " " into field "fItems"
  26.     FrecciaShortLog(0)
  27.     CheckSyncButton()
  28.   end if
  29. end
  30.  
  31. on AskForDestFolder
  32.   global gMultiAll, gSourceFolder, gDestFolder, gBottomFolder, gDestFolderList, gDestFileList
  33.   if gMultiAll then
  34.     GoMulti()
  35.   else
  36.     if (gDestFolder <> EMPTY) and (OSIsDirectory(gDestFolder) = 1) then
  37.       dosSetCurrentFolder(ExtractParentFolder(gDestFolder))
  38.     end if
  39.     set TempgDestFolder to OSSelectFolder()
  40.     if TempgDestFolder = 0 then
  41.       exit
  42.     end if
  43.     if TempgDestFolder = gSourceFolder then
  44.       AlertBox("You cannot choose the same Folder two times.")
  45.       exit
  46.     end if
  47.     set gBottomFolder to TempgDestFolder
  48.     set gDestFolder to TempgDestFolder
  49.     set gDestFolderList to []
  50.     set gDestFileList to []
  51.     put AccorciaNome(gDestFolder) into field "fDestFolder"
  52.     put " " into field "fItems"
  53.     FrecciaShortLog(0)
  54.     CheckSyncButton()
  55.   end if
  56. end
  57.  
  58. on GetSourceFolder
  59.   global gFolderList, gFileList, gSourceFolder, gSourceFolderList, gSourceFileList
  60.   set gFolderList to []
  61.   set gFileList to []
  62.   ScanFolders(gSourceFolder)
  63.   deleteAt(gFolderList, 1)
  64.   set gSourceFolderList to gFolderList
  65.   set gSourceFileList to gFileList
  66.   set gFolderList to []
  67.   set gFileList to []
  68. end
  69.  
  70. on GetDestFolder
  71.   global gFolderList, gFileList, gDestFolder, gDestFolderList, gDestFileList
  72.   set gFolderList to []
  73.   set gFileList to []
  74.   ScanFolders(gDestFolder)
  75.   deleteAt(gFolderList, 1)
  76.   set gDestFolderList to gFolderList
  77.   set gDestFileList to gFileList
  78.   set gFolderList to []
  79.   set gFileList to []
  80. end
  81.  
  82. on ScanFolders myFolder
  83.   global gFolderList, gInvisible, gRegisteredCopy, gNumTotFiles, gMaxUnreg, gFilterAll, gFilterScript, gPrBarIter
  84.   append(gFolderList, myFolder)
  85.   set listaItems to OSGetFileNamesinFolder(myFolder, gInvisible)
  86.   if listaItems = EMPTY then
  87.     exit
  88.   end if
  89.   set totItems to the number of lines in listaItems
  90.   repeat with i = 1 to totItems
  91.     if the mouseDown and (the rollOver = 13) and (field "P4" = "Stop") then
  92.       pass()
  93.     end if
  94.     set myItem to myFolder & line i of listaItems
  95.     if myItem = myFolder then
  96.       set myItem to myFolder & line i - 1 of listaItems & RETURN
  97.     end if
  98.     if OSIsDirectory(myItem) = 1 then
  99.       ScanFolders(myItem)
  100.     else
  101.       if OSIsDirectory(myItem) = 0 then
  102.         if (gRegisteredCopy = 0) and (gNumTotFiles >= gMaxUnreg) then
  103.           StoppaUnregistered()
  104.         end if
  105.         if gFilterAll and (gFilterScript <> EMPTY) then
  106.           if FilterThis(myItem) then
  107.             set gNumTotFiles to gNumTotFiles + 1
  108.             append(gFileList, myItem)
  109.             put "Files Found:" && gNumTotFiles into field "fItems"
  110.           end if
  111.         else
  112.           set gNumTotFiles to gNumTotFiles + 1
  113.           append(gFileList, myItem)
  114.           put "Files Found:" && gNumTotFiles into field "fItems"
  115.         end if
  116.       end if
  117.     end if
  118.     set gPrBarIter to gPrBarIter + 1
  119.     set the locH of sprite 2 to 147 + (gPrBarIter mod 16)
  120.     updateStage()
  121.   end repeat
  122. end
  123.  
  124. on AskSyncronizza
  125.   global gOneDirection, gMultiAll, gSourceFolder, gDestFolder, gAskConfirm
  126.   if NoSelectedFolders() then
  127.     exit
  128.   end if
  129.   if gOneDirection then
  130.     set theTask to "BackUp"
  131.   else
  132.     set theTask to "Synchronize"
  133.   end if
  134.   if not gAskConfirm then
  135.     if gMultiAll then
  136.       DoMultiSynchronize()
  137.     else
  138.       DoSingleSynchronize()
  139.     end if
  140.   else
  141.     if gMultiAll then
  142.       DialogBoxSiNo("Would you " & theTask & " from Multiple List?", "DoMultiSynchronize", "nothing")
  143.     else
  144.       DialogBoxSiNo("Would you " & theTask & " folder" && QUOTE & ExtractFileNameFromPath(gSourceFolder) & QUOTE && "with" && QUOTE & ExtractFileNameFromPath(gDestFolder) & QUOTE & "?", "DoSingleSynchronize", "nothing")
  145.     end if
  146.   end if
  147. end
  148.  
  149. on DoSynchronize
  150.   global gMultiAll
  151.   if gMultiAll then
  152.     set err to DoMultiSynchronize()
  153.   else
  154.     set err to DoSingleSynchronize()
  155.   end if
  156.   return err
  157. end
  158.  
  159. on DoSingleSynchronize
  160.   PreSynchronizing()
  161.   set err to DoOneSynchronize()
  162.   FineSingleSync()
  163.   return err
  164. end
  165.  
  166. on PreSynchronizing
  167.   global gTimerAll, gStopTimerAll, gFilterAll, gIterMulti, gShortReportList, gLogPathList
  168.   updateStage()
  169.   set gIterMulti to 0
  170.   set gStopTimerAll to gTimerAll
  171.   set gTimerAll to 0
  172.   set gShortReportList to []
  173.   set gLogPathList to []
  174.   if gFilterAll then
  175.     CompactFilters()
  176.   end if
  177. end
  178.  
  179. on FineSingleSync
  180.   global gOneDirection, gSourceFolder, gDestFolder, gAFilesCopied, gAFilesReplaced, gBFilesCopied, gBFilesReplaced, gTimerAll, gStopTimerAll, gBeepWhenDone, gLastBackUpDate
  181.   put " " into field "fItems"
  182.   put MyOperationBtn() into field "P4"
  183.   put " " into field "fItems"
  184.   set mySourceName to AccorciaNome(gSourceFolder, 35)
  185.   set myDestName to AccorciaNome(gDestFolder, 35)
  186.   set bfiles to string(gBFilesCopied + gBFilesReplaced)
  187.   set afiles to string(gAFilesCopied + gAFilesReplaced)
  188.   put "Files copied into:" & RETURN into field "fItems"
  189.   if gOneDirection <> 1 then
  190.     put "‚Ä¢" && mySourceName & ":" && afiles & RETURN after field "fItems"
  191.   end if
  192.   put "‚Ä¢" && myDestName & ":" && bfiles & RETURN after field "fItems"
  193.   FrecciaShortLog(1)
  194.   set gLastBackUpDate to [TodayYear(1), TodayMonth(1), TodayDay(1)]
  195.   cursor(-1)
  196.   set gTimerAll to gStopTimerAll
  197.   beep(gBeepWhenDone)
  198.   return 0
  199. end
  200.  
  201. on DoOneSynchronize
  202.   global gSourceFolderList, gSourceFileList, gDestFolderList, gDestFileList, gShortTextLog, gShortReportList, gBigTextLog, gSaveLogFile
  203.   updateStage()
  204.   SetHeaderLogFile()
  205.   set err to NoValidFolders()
  206.   if err then
  207.     return err
  208.   end if
  209.   FrecciaShortLog(0)
  210.   cursor(4)
  211.   AzzeraCounters()
  212.   ShowProgressBar()
  213.   GetSourceFolder()
  214.   GetDestFolder()
  215.   EraseDestItems()
  216.   HideInfiniteProgressBar()
  217.   CoreSynch()
  218.   PurgeAftertask()
  219.   return 0
  220. end
  221.  
  222. on PurgeAftertask
  223.   global gSourceFolderList, gSourceFileList, gDestFolderList, gDestFileList, gShortTextLog, gShortReportList, gBigTextLog, gSaveLogFile
  224.   HideInfiniteProgressBar()
  225.   HideProgressBar()
  226.   set TextReport to SetFooterLogFile()
  227.   set gSourceFolderList to []
  228.   set gSourceFileList to []
  229.   set gDestFolderList to []
  230.   set gDestFileList to []
  231.   put TextReport after gShortTextLog
  232.   append(gShortReportList, gShortTextLog)
  233.   put "--" & RETURN after gBigTextLog
  234.   put TextReport after gBigTextLog
  235.   if gSaveLogFile then
  236.     SaveLogFile()
  237.   end if
  238.   set gBigTextLog to EMPTY
  239. end
  240.  
  241. on AbortSync message
  242.   global gScambioFolders, gOneDirection, gSaveLogFile, gMultiAll, gTimerAll, gStopTimerAll, gShortReportList, gShortTextLog, gBigTextLog, gDoAndQuit, gJustLaunched
  243.   if message starts "User pressed" then
  244.     set byUser to 1
  245.   else
  246.     set byUser to 0
  247.   end if
  248.   if not voidp(message) and (message <> EMPTY) then
  249.     put message & RETURN after gBigTextLog
  250.     put message & RETURN after gShortTextLog
  251.   end if
  252.   if gScambioFolders = 1 then
  253.     ScambiaCartelle()
  254.   end if
  255.   put " " into field "fItems"
  256.   put MyOperationBtn() into field "P4"
  257.   PurgeAftertask()
  258.   if not byUser then
  259.     set gStopTimerAll to 0
  260.     SpegniTimer()
  261.   end if
  262.   if gMultiAll then
  263.     FineMultiSync()
  264.   else
  265.     FineSingleSync()
  266.   end if
  267.   if gDoAndQuit and gJustLaunched then
  268.     quit()
  269.   else
  270.     abort()
  271.   end if
  272. end
  273.  
  274. on CoreSynch
  275.   global gBigTextLog, gScambioFolders, gOneDirection, gAFoldersCreated, gAFilesRenamed, gAFilesCopied, gAFilesReplaced, gBFoldersCreated, gBFilesRenamed, gBFilesCopied, gBFilesReplaced, gTotFoldCreated, gTotFileRenamed, gTotFileCopied, gTotFileReplaced
  276.   set gScambioFolders to 0
  277.   repeat with mySwap = 1 to 2
  278.     put "--" & RETURN after gBigTextLog
  279.     SyncFolders()
  280.     if gScambioFolders = 0 then
  281.       set gBFilesRenamed to gTotFileRenamed
  282.     else
  283.       set gAFilesRenamed to gAFilesRenamed + gTotFileRenamed
  284.     end if
  285.     set gTotFileRenamed to 0
  286.     SyncFiles()
  287.     if gScambioFolders = 0 then
  288.       set gAFilesRenamed to gTotFileRenamed
  289.       set gBFoldersCreated to gTotFoldCreated
  290.       set gBFilesCopied to gTotFileCopied
  291.       set gBFilesReplaced to gTotFileReplaced
  292.     else
  293.       set gBFilesRenamed to gBFilesRenamed + gTotFileRenamed
  294.       set gAFoldersCreated to gTotFoldCreated
  295.       set gAFilesCopied to gTotFileCopied
  296.       set gAFilesReplaced to gTotFileReplaced
  297.     end if
  298.     set gTotFoldCreated to 0
  299.     set gTotFileRenamed to 0
  300.     set gTotFileCopied to 0
  301.     set gTotFileReplaced to 0
  302.     if gOneDirection = 1 then
  303.       exit repeat
  304.     end if
  305.     ScambiaCartelle()
  306.     set gScambioFolders to gScambioFolders + 1
  307.   end repeat
  308. end
  309.  
  310. on FrecciaShortLog myFlag
  311.   if myFlag then
  312.     set the locV of sprite 18 to 135
  313.   else
  314.     set the locV of sprite 18 to -1000
  315.   end if
  316.   updateStage()
  317. end
  318.  
  319. on AzzeraCounters
  320.   global gSourceFolderList, gSourceFileList, gDestFolderList, gDestFileList, gNumTotFiles, gPrBarIter, gTotError, gScambioFolders, gTotFoldCreated, gTotFileRenamed, gTotFileCopied, gTotFileReplaced, gAFoldersCreated, gAFilesRenamed, gAFilesCopied, gAFilesReplaced, gBFoldersCreated, gBFilesRenamed, gBFilesCopied, gBFilesReplaced
  321.   set gSourceFolderList to []
  322.   set gSourceFileList to []
  323.   set gDestFolderList to []
  324.   set gDestFileList to []
  325.   set gNumTotFiles to 0
  326.   set gPrBarIter to 0
  327.   set gTotError to 0
  328.   set gScambioFolders to 0
  329.   set gTotFoldCreated to 0
  330.   set gTotFileRenamed to 0
  331.   set gTotFileCopied to 0
  332.   set gTotFileReplaced to 0
  333.   set gAFoldersCreated to 0
  334.   set gAFilesRenamed to 0
  335.   set gAFilesCopied to 0
  336.   set gAFilesReplaced to 0
  337.   set gBFoldersCreated to 0
  338.   set gBFilesRenamed to 0
  339.   set gBFilesCopied to 0
  340.   set gBFilesReplaced to 0
  341. end
  342.  
  343. on EraseDestItems
  344.   global gOneDirection, gDestructive, gBigTextLog, gSep, gPrBarIter, gTotErasedFiles, gDestFileList, gSourceFileList, gUnlockFile, gTotErasedFolders, gDestFolderList, gSourceFolderList, gOnErrorDo, gTotError
  345.   if (gOneDirection = 0) or (gDestructive = 0) then
  346.     exit
  347.   end if
  348.   put "--" & RETURN after gBigTextLog
  349.   put "Scan to delete items..." into field "fItems"
  350.   set oldDelimiter to the itemDelimiter
  351.   set the itemDelimiter to gSep
  352.   set gTotErasedFiles to 0
  353.   repeat with myFile in gDestFileList
  354.     if the mouseDown and (the rollOver = 13) and (field "P4" = "Stop") then
  355.       pass()
  356.     end if
  357.     if getPos(gSourceFileList, DestToSourceFolder(myFile)) = 0 then
  358.       set fileIsLocked to dosGetFileAttribute(myFile, "Read Only")
  359.       if gUnlockFile and fileIsLocked then
  360.         OSSetFileLock(myFile, 0)
  361.       end if
  362.       set err to OSDelete(myFile)
  363.       if err then
  364.         if fileIsLocked then
  365.           set myLock to " locked"
  366.         else
  367.           set myLock to EMPTY
  368.         end if
  369.         case gOnErrorDo of
  370.           0:
  371.             set the itemDelimiter to oldDelimiter
  372.             set message to "Cannot delete the" & myLock & " file" && QUOTE & AccorciaNome(myFile, 60) & QUOTE & "." & MsgTimer()
  373.             AlertBox(message)
  374.             AbortSync(message)
  375.           1:
  376.             set gTotError to gTotError + 1
  377.             put "¬Ø Error " & gTotError & ": Cannot delete the" & myLock & " file:" & RETURN & myFile & RETURN after gBigTextLog
  378.           2:
  379.             nothing()
  380.         end case
  381.       else
  382.         set gTotErasedFiles to gTotErasedFiles + 1
  383.         put "Files Deleted:" && gTotErasedFiles into field "fItems"
  384.         put "Deleted File:" & RETURN & myFile & RETURN after gBigTextLog
  385.       end if
  386.     end if
  387.     set gPrBarIter to gPrBarIter + 1
  388.     set the locH of sprite 2 to 147 + (gPrBarIter mod 16)
  389.     updateStage()
  390.   end repeat
  391.   set gTotErasedFolders to 0
  392.   set MaxFolders to count(gDestFolderList)
  393.   repeat with k = 0 to MaxFolders - 1
  394.     if the mouseDown and (the rollOver = 13) and (field "P4" = "Stop") then
  395.       pass()
  396.     end if
  397.     set i to MaxFolders - k
  398.     set myFolder to getAt(gDestFolderList, i)
  399.     if getPos(gSourceFolderList, DestToSourceFolder(myFolder)) = 0 then
  400.       set ok to dosDeleteFolder(myFolder)
  401.       if ok = 0 then
  402.         set the itemDelimiter to oldDelimiter
  403.         set message to "Cannot delete the folder" && QUOTE & AccorciaNome(myFolder, 60) & QUOTE & "." & MsgTimer()
  404.         AlertBox(message)
  405.         AbortSync(message)
  406.       end if
  407.       set gTotErasedFolders to gTotErasedFolders + 1
  408.       put "Folders Deleted:" && gTotErasedFolders into field "fItems"
  409.       put "Deleted Folder:" & RETURN & myFolder & RETURN after gBigTextLog
  410.     end if
  411.     set gPrBarIter to gPrBarIter + 1
  412.     set the locH of sprite 2 to 147 + (gPrBarIter mod 16)
  413.     updateStage()
  414.   end repeat
  415.   set the itemDelimiter to oldDelimiter
  416. end
  417.  
  418. on ScambiaCartelle
  419.   global gSourceFolderList, gDestFolderList, gSourceFileList, gDestFileList, gSourceFolder, gDestFolder
  420.   set TgSourceFolderList to gSourceFolderList
  421.   set gSourceFolderList to gDestFolderList
  422.   set gDestFolderList to TgSourceFolderList
  423.   set TgSourceFileList to gSourceFileList
  424.   set gSourceFileList to gDestFileList
  425.   set gDestFileList to TgSourceFileList
  426.   set TgSourceFolder to gSourceFolder
  427.   set gSourceFolder to gDestFolder
  428.   set gDestFolder to TgSourceFolder
  429. end
  430.  
  431. on SyncFolders
  432.   global gSep, gSourceFolder, gDestFolder, gSourceFolderList, gDestFileList, gUnlockFile, gOnErrorDo, gTotFileRenamed, gTotFoldCreated, gTotError, gBigTextLog
  433.   set oldDelimiter to the itemDelimiter
  434.   set the itemDelimiter to gSep
  435.   set s to the number of items in gSourceFolder - 1
  436.   set SemiDestFold to item 1 to the number of items in gDestFolder - 1 of gDestFolder
  437.   set mySourceFolderName to ExtractFileNameFromPath(gSourceFolder)
  438.   set myDestFolderName to ExtractFileNameFromPath(gDestFolder)
  439.   set Predict to "Folders from" && QUOTE & mySourceFolderName & QUOTE && "to" && QUOTE & myDestFolderName & QUOTE & ":"
  440.   set sourceFolderCount to count(gSourceFolderList)
  441.   if sourceFolderCount = 0 then
  442.     exit
  443.   end if
  444.   set blockSourceFolderCount to sourceFolderCount
  445.   set H to (the width of member "myProgBack" - 3) / float(sourceFolderCount)
  446.   put " " into field "fItems"
  447.   set the loc of sprite 3 to point(48, 150)
  448.   set the loc of sprite 4 to point(-71, 150)
  449.   updateStage()
  450.   repeat with j = 1 to count(gSourceFolderList)
  451.     set sourceFold to getAt(gSourceFolderList, j)
  452.     if the mouseDown and (the rollOver = 13) and (field "P4" = "Stop") then
  453.       pass()
  454.     end if
  455.     set destFold to sourceFold
  456.     put SemiDestFold into item 1 to s of destFold
  457.     if OSIsDirectory(destFold) = 0 then
  458.       set OldFile to destFold
  459.       delete char -30000 of OldFile
  460.       set newPathName to GetUniquePathNameInFolder(OldFile)
  461.       set NewName to ExtractFileNameFromPath(newPathName)
  462.       set modifLock to 0
  463.       set fileIsLocked to dosGetFileAttribute(OldFile, "Read Only")
  464.       if gUnlockFile and fileIsLocked then
  465.         OSSetFileLock(OldFile, 0)
  466.         set modifLock to 1
  467.       end if
  468.       set err to OSRename(OldFile, NewName)
  469.       if err then
  470.         if fileIsLocked then
  471.           set myLock to " locked"
  472.         else
  473.           set myLock to EMPTY
  474.         end if
  475.         case gOnErrorDo of
  476.           0:
  477.             set message to "Error renaming the" & myLock & " file" && QUOTE & AccorciaNome(OldFile, 60) & QUOTE & "." & MsgTimer()
  478.             AlertBox(message)
  479.             AbortSync(message)
  480.           1:
  481.             set gTotError to gTotError + 1
  482.             put "¬Ø Error " & gTotError & ": Cannot rename the" & myLock & " file:" & RETURN & OldFile && "with new name" & RETURN & newPathName & RETURN after gBigTextLog
  483.           2:
  484.             nothing()
  485.         end case
  486.       else
  487.         set gTotFileRenamed to gTotFileRenamed + 1
  488.         put "Renamed File:" & RETURN & OldFile && "with new name" & RETURN & newPathName & RETURN after gBigTextLog
  489.         setAt(gDestFileList, getPos(gDestFileList, OldFile), newPathName)
  490.       end if
  491.       if modifLock = 1 then
  492.         OSSetFileLock(newPathName, 1)
  493.       end if
  494.     end if
  495.     if OSIsDirectory(destFold) <> 1 then
  496.       OSCreateDir(ExtractParentFolder(destFold), ExtractFileNameFromPath(destFold))
  497.       set err to OSIsDirectory(destFold) <> 1
  498.       if err = 0 then
  499.         set gTotFoldCreated to gTotFoldCreated + 1
  500.         put "Created Dir:" & RETURN & destFold & RETURN after gBigTextLog
  501.         set comm to OSGetComment(sourceFold)
  502.         if stringp(comm) then
  503.           OSSetComment(destFold, comm)
  504.         end if
  505.       else
  506.         case gOnErrorDo of
  507.           0:
  508.             set message to "Error creating folder" && QUOTE & AccorciaNome(destFold, 60) & QUOTE & "." & MsgTimer()
  509.             AlertBox(message)
  510.             AbortSync(message)
  511.           1:
  512.             set gTotError to gTotError + 1
  513.             put "¬Ø Error " & gTotError & ": Cannot create the folder:" & RETURN & destFold & RETURN after gBigTextLog
  514.           2:
  515.             nothing()
  516.         end case
  517.       end if
  518.     end if
  519.     set sourceFolderCount to sourceFolderCount - 1
  520.     put Predict && sourceFolderCount into field "fItems"
  521.     set the locH of sprite 4 to -71 + (H * (blockSourceFolderCount - sourceFolderCount))
  522.     if (H * (blockSourceFolderCount - sourceFolderCount)) < 8 then
  523.       set the locH of sprite 3 to 48 + (H * (blockSourceFolderCount - sourceFolderCount))
  524.     end if
  525.     updateStage()
  526.   end repeat
  527.   set the itemDelimiter to oldDelimiter
  528. end
  529.  
  530. on SyncFiles
  531.   global gSep, gSourceFolder, gDestFolder, gSourceFileList, gTotFileCopied, gUnlockFile, gTotFileRenamed, gOnErrorDo, gTotError, gBigTextLog
  532.   set oldDelimiter to the itemDelimiter
  533.   set the itemDelimiter to gSep
  534.   set s to the number of items in gSourceFolder - 1
  535.   set SemiDestFold to item 1 to the number of items in gDestFolder - 1 of gDestFolder
  536.   set mySourceFolderName to ExtractFileNameFromPath(gSourceFolder)
  537.   set myDestFolderName to ExtractFileNameFromPath(gDestFolder)
  538.   set Predict to "Files from" && QUOTE & mySourceFolderName & QUOTE && "to" && QUOTE & myDestFolderName & QUOTE & ":"
  539.   set sourceFileCount to count(gSourceFileList)
  540.   if sourceFileCount = 0 then
  541.     exit
  542.   end if
  543.   set blockSourceFileCount to sourceFileCount
  544.   set H to (the width of member "myProgBack" - 3) / float(sourceFileCount)
  545.   put " " into field "fItems"
  546.   set the loc of sprite 3 to point(48, 150)
  547.   set the loc of sprite 4 to point(-71, 150)
  548.   updateStage()
  549.   repeat with sourceFile in gSourceFileList
  550.     if the mouseDown and (the rollOver = 13) and (field "P4" = "Stop") then
  551.       pass()
  552.     end if
  553.     set destFile to sourceFile
  554.     put SemiDestFold into item 1 to s of destFile
  555.     if OSIsDirectory(destFile) = 0 then
  556.       if ConfrontaRecenteFile(sourceFile, destFile) = 1 then
  557.         RimpiazzaFile(sourceFile, destFile)
  558.       end if
  559.     else
  560.       if OSIsDirectory(destFile) < 0 then
  561.         set err to OSFileCopy(sourceFile, destFile)
  562.         if err then
  563.           case gOnErrorDo of
  564.             0:
  565.               set message to "Error copying file" && QUOTE & AccorciaNome(sourceFile, 60) & QUOTE & "." & MsgTimer()
  566.               AlertBox(message)
  567.               AbortSync(message)
  568.             1:
  569.               set gTotError to gTotError + 1
  570.               put "¬Ø Error " & gTotError & ": Cannot copy the file from:" & RETURN & sourceFile && "to:" & RETURN & destFile & RETURN after gBigTextLog
  571.             2:
  572.               nothing()
  573.           end case
  574.         else
  575.           set gTotFileCopied to gTotFileCopied + 1
  576.           put "Copied File from:" & RETURN & sourceFile && "into" & RETURN & destFile & RETURN after gBigTextLog
  577.         end if
  578.       else
  579.         if OSIsDirectory(destFile) = 1 then
  580.           set parID to ExtractParentFolder(sourceFile)
  581.           set fileName to ExtractFileNameFromPath(sourceFile)
  582.           set newPathName to sourceFile
  583.           set k to 0
  584.           repeat while (OSIsDirectory(newPathName) >= 0) or (OSIsDirectory(SourceToDestFolder(newPathName)) >= 0)
  585.             set k to k + 1
  586.             set lun to 30 - length(string(k))
  587.             set newPathName to parID & Sinistra(fileName, lun) & "." & string(k)
  588.           end repeat
  589.           set NewName to ExtractFileNameFromPath(newPathName)
  590.           set modifLock to 0
  591.           if gUnlockFile and (dosGetFileAttribute(sourceFile, "Read Only") = 1) then
  592.             OSSetFileLock(sourceFile, 0)
  593.             set modifLock to 1
  594.           end if
  595.           set err to OSRename(sourceFile, NewName)
  596.           if err then
  597.             case gOnErrorDo of
  598.               0:
  599.                 set message to "Error renaming file" && QUOTE & AccorciaNome(sourceFile, 60) & QUOTE & "." & MsgTimer()
  600.                 AlertBox(message)
  601.                 AbortSync(message)
  602.               1:
  603.                 set gTotError to gTotError + 1
  604.                 put "¬Ø Error " & gTotError & ": Cannot rename the file:" & RETURN & sourceFile && "with new name" & RETURN & newPathName & RETURN after gBigTextLog
  605.               2:
  606.                 nothing()
  607.             end case
  608.           else
  609.             set gTotFileRenamed to gTotFileRenamed + 1
  610.             put "Renamed File:" & RETURN & sourceFile && "with new name" & RETURN & newPathName & RETURN after gBigTextLog
  611.             setAt(gSourceFileList, getPos(gSourceFileList, parID & fileName), newPathName)
  612.           end if
  613.           if modifLock = 1 then
  614.             OSSetFileLock(newPathName, 1)
  615.           end if
  616.           set tempDest to ExtractParentFolder(destFile) & NewName
  617.           set err to OSFileCopy(newPathName, tempDest)
  618.           if err then
  619.             case gOnErrorDo of
  620.               0:
  621.                 set message to "Error copying file" && QUOTE & AccorciaNome(newPathName, 60) & QUOTE & "." & MsgTimer()
  622.                 AlertBox(message)
  623.                 AbortSync(message)
  624.               1:
  625.                 set gTotError to gTotError + 1
  626.                 put "¬Ø Error " & gTotError & ": Cannot copy the file:" & RETURN & newPathName && "into" & RETURN & tempDest & RETURN after gBigTextLog
  627.               2:
  628.                 nothing()
  629.             end case
  630.           else
  631.             set gTotFileCopied to gTotFileCopied + 1
  632.             put "Copied File:" & RETURN & newPathName && "into" & RETURN & tempDest & RETURN after gBigTextLog
  633.           end if
  634.         end if
  635.       end if
  636.     end if
  637.     set sourceFileCount to sourceFileCount - 1
  638.     put Predict && sourceFileCount into field "fItems"
  639.     set the locH of sprite 4 to -71 + (H * (blockSourceFileCount - sourceFileCount))
  640.     if (H * (blockSourceFileCount - sourceFileCount)) < 8 then
  641.       set the locH of sprite 3 to 48 + (H * (blockSourceFileCount - sourceFileCount))
  642.     end if
  643.     updateStage()
  644.   end repeat
  645. end
  646.  
  647. on RimpiazzaFile sourceF, destF
  648.   global gUnlockFile, gTotFileReplaced, gOnErrorDo, gTotError, gBigTextLog
  649.   set myParID to ExtractParentFolder(destF)
  650.   set TempFileName to "TempFileFoldersSynchronizer"
  651.   set TempFile to myParID & TempFileName
  652.   set destFileName to ExtractFileNameFromPath(destF)
  653.   if OSIsDirectory(TempFile) = 0 then
  654.     OSSetFileLock(TempFile, 0)
  655.     set err to OSDelete(TempFile)
  656.     if err then
  657.       case gOnErrorDo of
  658.         0:
  659.           set message to "Error deleting temp file" && QUOTE & AccorciaNome(TempFile, 60) & QUOTE & "." & MsgTimer()
  660.           AlertBox(message)
  661.           AbortSync(message)
  662.         1:
  663.           set gTotError to gTotError + 1
  664.           put "¬Ø Error " & gTotError & ": Cannot delete the Temp File:" & RETURN & TempFile & RETURN after gBigTextLog
  665.         2:
  666.           nothing()
  667.       end case
  668.     end if
  669.   end if
  670.   if (gUnlockFile = 0) and (dosGetFileAttribute(destF, "Read Only") = 1) then
  671.     case gOnErrorDo of
  672.       0:
  673.         set message to "Cannot replace the locked file" && QUOTE & AccorciaNome(destF, 60) & QUOTE & "." & MsgTimer()
  674.         AlertBox(message)
  675.         AbortSync(message)
  676.       1:
  677.         set gTotError to gTotError + 1
  678.         put "¬Ø Error " & gTotError & ": Cannot replace the locked file:" & RETURN & destF & RETURN after gBigTextLog
  679.       2:
  680.         nothing()
  681.     end case
  682.     exit
  683.   end if
  684.   set err to OSFileCopy(sourceF, TempFile)
  685.   if err then
  686.     if dosGetFileAttribute(sourceF, "Read Only") = 1 then
  687.       set IsLockedSource to " locked"
  688.     else
  689.       set IsLockedSource to EMPTY
  690.     end if
  691.     case gOnErrorDo of
  692.       0:
  693.         set message to "Error coping" & IsLockedSource & " file" && QUOTE & AccorciaNome(sourceF, 60) & QUOTE & "." & MsgTimer()
  694.         AlertBox(message)
  695.         AbortSync(message)
  696.       1:
  697.         set gTotError to gTotError + 1
  698.         put "¬Ø Error " & gTotError & ": Cannot copy the" & IsLockedSource & " file:" & RETURN & sourceF & " into:" & RETURN & TempFile & RETURN after gBigTextLog
  699.       2:
  700.         nothing()
  701.     end case
  702.     exit
  703.   end if
  704.   OSSetFileLock(TempFile, 0)
  705.   set wasLocked to dosGetFileAttribute(destF, "Read Only")
  706.   if gUnlockFile then
  707.     OSSetFileLock(destF, 0)
  708.   end if
  709.   set err to OSDelete(destF)
  710.   if err then
  711.     OSDelete(TempFile)
  712.     OSSetFileLock(destF, wasLocked)
  713.     if wasLocked then
  714.       set IsLockedDest to " locked"
  715.     else
  716.       set IsLockedDest to EMPTY
  717.     end if
  718.     case gOnErrorDo of
  719.       0:
  720.         set message to "Error deleting" & IsLockedDest & " file" && QUOTE & AccorciaNome(destF, 60) & QUOTE & "." & MsgTimer()
  721.         AlertBox(message)
  722.         AbortSync(message)
  723.       1:
  724.         set gTotError to gTotError + 1
  725.         put "¬Ø Error " & gTotError & ": Cannot delete the" & IsLockedDest & " file:" & RETURN & destF & RETURN after gBigTextLog
  726.       2:
  727.         nothing()
  728.     end case
  729.     exit
  730.   end if
  731.   set err to OSRename(TempFile, destFileName)
  732.   if dosGetFileAttribute(sourceF, "Read Only") = 1 then
  733.     OSSetFileLock(destF, 1)
  734.   end if
  735.   if err then
  736.     if dosGetFileAttribute(destF, "Read Only") = 1 then
  737.       set IsLockedDest to " locked"
  738.     else
  739.       set IsLockedDest to EMPTY
  740.     end if
  741.     case gOnErrorDo of
  742.       0:
  743.         set message to "Error renaming" & IsLockedDest & " file" && QUOTE & AccorciaNome(TempFile, 60) & QUOTE & "." & MsgTimer()
  744.         AlertBox(message)
  745.         AbortSync(message)
  746.       1:
  747.         set gTotError to gTotError + 1
  748.         put "¬Ø Error " & gTotError & ": Cannot rename the" & IsLockedDest & " Temp file:" & RETURN & TempFile & " to: " & destFileName & RETURN after gBigTextLog
  749.       2:
  750.         nothing()
  751.     end case
  752.   else
  753.     set gTotFileReplaced to gTotFileReplaced + 1
  754.     put "Replaced old file:" & RETURN & destF && "with new file from" & RETURN & sourceF & RETURN after gBigTextLog
  755.   end if
  756. end
  757.