/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ var iWinW = 400;; var iWinH = 305;; fun cDsMainWin(winstr)= _closemachine; 0;; fun cbDlgGetPath(dlg, p, pfile)= let p -> [ctrlpath ctrlppath ctrlbtn] in ( if pfile == nil then nil else let _PtoScol pfile -> file in if file == nil then ( _DLGMessageBox _channel mainWindow.EDW_win "Error" "Your file have to be in a scol partition." 0; 0; ) else ( setEdCtrlTextLineValue ctrlpath file; let getPathFile file "" -> [fpath fname] in setEdCtrlTextLineValue ctrlppath fpath; 0; ); setEdCtrlButtonEnable ctrlbtn 1; ); 0;; fun cbBtnPickFile(ctrlbtn, p)= let p -> [ctrlpath ctrlppath] in let getEdCtrlTextLineValue ctrlpath -> path in let getPathFile path "" -> [fpath fname] in ( setEdCtrlButtonEnable ctrlbtn 0; _DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win fpath fname "OpenSpace3D\0*.xos\0All\0*.*\0\0" @cbDlgGetPath [ctrlpath ctrlppath ctrlbtn]; ); 0;; fun unzipProjectFile(path)= let (_checkpack path) -> pfile in let _getpack pfile -> fcont in let if (!strcmp "ZXML" (substr fcont 0 4)) then 1 else 0 -> iszipped in let if iszipped then unzip (substr fcont 4 (strlen fcont)-4) else fcont -> fcont in ( _storepack fcont path; ); 0;; fun cbBtnUnzip(ctrlbtn, p)= let p -> [ctrlpath ctrlbdir] in let getEdCtrlTextLineValue ctrlpath -> path in let getEdCtrlTextLineValue ctrlbdir -> sdir in if ((strlen path) == 0) then ( if ((strlen sdir) == 0) then nil else ( let if (!strcmp (substr sdir 0 1) "/") then substr sdir 1 (strlen sdir) - 1 else sdir -> sdir in let getFilesFromDirFilterRecursive2 sdir "xos"::nil nil -> lfiles in while (lfiles != nil) do ( unzipProjectFile (hd lfiles); set lfiles = tl lfiles; ); _DLGMessageBox _channel mainWindow.EDW_win "Done" "Your files have been rewrited unziped." 0; ); 0; ) else ( unzipProjectFile path; _DLGMessageBox _channel mainWindow.EDW_win "Done" "Your file have been rewrited unziped." 0; 0; ); 0;; fun replaceProjectPaths(path, ppath, npath)= let (_checkpack path) -> pfile in let _getpack pfile -> fcont in let if (!strcmp "ZXML" (substr fcont 0 4)) then 1 else 0 -> iszipped in let if iszipped then unzip (substr fcont 4 (strlen fcont)-4) else fcont -> fcont in let strreplacei fcont ppath npath -> ndata in let strreplacei ndata strtoweb ppath strtoweb npath -> ndata in let if iszipped then strcat "ZXML" zip ndata else ndata -> content in _storepack content path; 0;; fun cbBtnReplace(ctrlbtn, p)= let p -> [ctrlpath ctrlbdir ctrlppath ctrlnpath] in let getEdCtrlTextLineValue ctrlpath -> path in let strlowercase getEdCtrlTextLineValue ctrlppath -> ppath in let strlowercase getEdCtrlTextLineValue ctrlnpath -> npath in let getEdCtrlTextLineValue ctrlbdir -> sdir in if ((strlen ppath) == 0) then nil else ( if ((strlen path) == 0) then ( if ((strlen sdir) == 0) then nil else ( let if (!strcmp (substr sdir 0 1) "/") then substr sdir 1 (strlen sdir) - 1 else sdir -> sdir in let getFilesFromDirFilterRecursive2 sdir "xos"::nil nil -> lfiles in while (lfiles != nil) do ( replaceProjectPaths (hd lfiles) ppath npath; set lfiles = tl lfiles; ); _DLGMessageBox _channel mainWindow.EDW_win "Done" "Your files have been rewrited with replaced paths." 0; ); 0; ) else ( replaceProjectPaths path ppath npath; _DLGMessageBox _channel mainWindow.EDW_win "Done" "Your file have been rewrited with replaced paths." 0; 0; ); ); 0;; fun makeTplProject(path)= let XMLload path -> xmlscenestr in if (xmlscenestr == nil) then nil else ( let XMLgetMarkByValue xmlscenestr "scene" -> srcgroupmark in let XMLgetMarksByValue xmlscenestr "group" -> lgroups in let XMLgetMarkByValueFromMarkSons srcgroupmark "graph" -> graphstr in let if ((graphstr.XMLsons == nil) && ((sizelist lgroups) == 0)) then "plugitTemplate" else "dynamicTemplate" -> tplmode in let XMLgetMarkByValue xmlscenestr "project" -> srcprjmark in let XMLgetMarkByValueFromMarkSons srcprjmark "setting" -> srcsettingmark in let if (srcsettingmark == nil) then XMLaddMark xmlscenestr "setting" srcprjmark nil nil else srcsettingmark -> srcsettingmark in let XMLgetMarkByValueFromMarkSons srcsettingmark "projectType" -> keymark in if (keymark == nil) then ( XMLaddMark xmlscenestr "projectType" srcsettingmark nil tplmode; 0; ) else ( XMLsetData keymark tplmode; 0; ); XMLwriteZipped xmlscenestr path; ); 0;; fun cbBtnMakeTpl(ctrlbtn, p)= let p -> [ctrlpath ctrlbdir] in let getEdCtrlTextLineValue ctrlpath -> path in let getEdCtrlTextLineValue ctrlbdir -> sdir in if ((strlen path) == 0) then ( if ((strlen sdir) == 0) then nil else ( let if (!strcmp (substr sdir 0 1) "/") then substr sdir 1 (strlen sdir) - 1 else sdir -> sdir in let getFilesFromDirFilterRecursive2 sdir "xos"::nil nil -> lfiles in while (lfiles != nil) do ( makeTplProject (hd lfiles); set lfiles = tl lfiles; ); _DLGMessageBox _channel mainWindow.EDW_win "Done" "Your files have been set as templates." 0; ); 0; ) else ( makeTplProject path; _DLGMessageBox _channel mainWindow.EDW_win "Done" "Your file have been set as templates." 0; 0; ); 0;; fun cbCtrlRadioUnzip(ctrlstr, state, p)= let p -> [proceedbtn ctrlpath ctrlbdir] in setEdCtrlButtonCb proceedbtn mkfun2 @cbBtnUnzip [ctrlpath ctrlbdir]; 0;; fun cbCtrlRadioReplace(ctrlstr, state, p)= let p -> [proceedbtn ctrlpath ctrlbdir ctrlppath ctrlnpath] in setEdCtrlButtonCb proceedbtn mkfun2 @cbBtnReplace [ctrlpath ctrlbdir ctrlppath ctrlnpath]; 0;; fun cbCtrlRadioTpl(ctrlstr, state, p)= let p -> [proceedbtn ctrlpath ctrlbdir] in setEdCtrlButtonCb proceedbtn mkfun2 @cbBtnMakeTpl [ctrlpath ctrlbdir]; 0;; fun main()= let _GETdesktopSize -> [sw sh] in set mainWindow = crEdMainWindow _channel nil ((sw / 2) - (iWinW / 2)) ((sh / 2) - (iWinH / 2)) iWinW iWinH nil "OpenSpace3D Relocate Project"; set mainWindow.EDW_modeFlag = mainWindow.EDW_modeFlag; setEdwindowCbDestroy mainWindow @cDsMainWin; let 10 -> ypos in let iWinW -> iw in let crEdWindow _channel mainWindow 0 0 iw 265 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW EDWIN_GROUP nil -> gwinstr in let crEdFrameWindow _channel gwinstr 0 0 iw 80 EDWIN_RESIZE_MW nil "File setting" "Minimize / Restore" -> winfrm in let crEdWindow _channel winfrm 0 18 iw 60 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 ((set ypos = 10) + 2) 160 20 "Project path" nil -> labelprj in let crEdCtrlTextLine winstr 195 ypos 170 20 "" nil EDWIN_RESIZE_MW -> ctrlpath in let crEdCtrlButton winstr 370 ypos 25 20 "..." EDWIN_RESIZE_LW -> pickfilebtn in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 160 20 "Batch projects folder" nil -> labelbprj in let crEdCtrlTextLine winstr 195 ypos 170 20 "" nil EDWIN_RESIZE_MW -> ctrlbdir in let crEdFrameWindow _channel gwinstr 0 0 iw 80 EDWIN_RESIZE_MW nil "Paths" "Minimize / Restore" -> winfrm in let crEdWindow _channel winfrm 0 18 iw 60 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 ((set ypos = 10) + 2) 180 20 "Previous resources base path" nil -> labelx in let crEdCtrlTextLine winstr 195 ypos 170 20 "" nil EDWIN_RESIZE_MW -> ctrlppath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 180 20 "New resources base path" nil -> labelxo in let crEdCtrlTextLine winstr 195 ypos 170 20 "" nil EDWIN_RESIZE_MW -> ctrlnpath in let crEdFrameWindow _channel gwinstr 0 0 iw 105 EDWIN_RESIZE_MW nil "Action" "Minimize / Restore" -> winfrm in let crEdWindow _channel winfrm 0 18 iw 85 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlRadio winstr 10 (set ypos = 10) (iw - 20) 20 "Unzip XOS projects" EDWIN_RESIZE_MW -> ctrlunzip in let crEdCtrlRadio winstr 10 (set ypos = ypos + 25) (iw - 20) 20 "Replace resources paths" EDWIN_RESIZE_MW -> ctrlreplace in let crEdCtrlRadio winstr 10 (set ypos = ypos + 25) (iw - 20) 20 "Set projects as template" EDWIN_RESIZE_MW -> ctrltpl in let crEdCtrlButton mainWindow ((iw / 2) -40) (iWinH - 30) 80 20 "Proceed" EDWIN_RESIZE_LW|EDWIN_RESIZE_RW|EDWIN_RESIZE_LH -> proceedbtn in ( setEdWindowMinimumSize mainWindow iWinW iWinH; setEdCtrlRadioCbState ctrlunzip mkfun3 @cbCtrlRadioUnzip [proceedbtn ctrlpath ctrlbdir]; setEdCtrlRadioCbState ctrlreplace mkfun3 @cbCtrlRadioReplace [proceedbtn ctrlpath ctrlbdir ctrlppath ctrlnpath]; setEdCtrlRadioCbState ctrltpl mkfun3 @cbCtrlRadioTpl [proceedbtn ctrlpath ctrlbdir]; setEdCtrlRadioState ctrlunzip 1; setEdCtrlTextLineEnable ctrlpath 0; setEdCtrlButtonCb pickfilebtn mkfun2 @cbBtnPickFile [ctrlpath ctrlppath]; setEdCtrlButtonCb proceedbtn mkfun2 @cbBtnUnzip [ctrlpath ctrlbdir]; ); 0;;