This source file includes following definitions.
- Action_MakeSH_Dialog
- Action_MakeSH_Run
1 #include <stdio.h>
2 #include <Locker.h>
3 #include <Directory.h>
4
5 #include "BL_File.h"
6 #include "BF_GUI_FilesPanel.h"
7 #include "BF_Dict.h"
8 #include "BF_Roster.h"
9 #include "BF_GUI_KeysMenu.h"
10 #include "BF_GUI_WinMain.h"
11
12
13 void BF_GUI_FilesPanel::Action_MakeSH_Dialog()
14 {
15
16 BL_String sStorePath;
17 BF_GUI_Panel *poDestPanel = poWinView->PanelOnTop(!bWinPos_OnLeft);
18 sStorePath = poDestPanel?poDestPanel->Path():Path();
19
20
21 BL_String sTargetPath(Path()),sSHName;
22 {
23 BF_Node *poNode = Nodes_Focus();
24 if(poNode){
25 sSHName = poNode->Name();
26 sSHName << ".sh";
27 sTargetPath << "/";
28 sTargetPath << poNode->Name();;
29 }else{
30 sSHName << "run.sh";
31 }
32 }
33
34 {
35 BF_GUI_Func_PanelsEnable(false);
36
37 BMessage oMessage(BF_MSG_FILEPANEL_MAKESH_RUN);
38 oMessage.AddPointer("bf_focus",this);
39
40 BF_GUI_Dialog *poDialog = new BF_GUI_Dialog(BRect(0,0,300,0),
41 BF_DictAt(BF_DICT_FILES_MKSHLINK),"dialog",oMessage,BG_GUI_DIALOG_WINRESIZE_MOVE_CENTER);
42 BRect oRect;
43
44 poDialog->LocalBounds(oRect);
45 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
46 BF_GUI_ViewEdit_Create(oRect,BF_DictAt(BF_DICT_TARGETFILE),poDialog,"bf_cTargetPath",
47 sTargetPath.String(),
48 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE);
49
50
51 oRect.top = oRect.bottom+5;
52 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
53 BF_GUI_ViewEdit_Create(oRect,BF_DictAt(BF_DICT_SCRIPTNAME),poDialog,"bf_cScriptName",
54 sSHName.String(),
55 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE);
56
57 oRect.top = oRect.bottom+5;
58 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
59 BF_GUI_ViewEdit_Create(oRect,BF_DictAt(BF_DICT_INFOLDER),poDialog,"bf_cStorePath",
60 sStorePath.String(),
61 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE);
62
63 oRect.top = oRect.bottom+5;
64 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
65 BF_GUI_ViewEdit_Create(oRect,BF_DictAt(BF_DICT_ARGS),poDialog,"bf_cArgs",
66 "",
67 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE);
68
69 oRect.top = oRect.bottom+5;
70 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
71 poDialog->AddChild(new BF_GUI_ViewCheck(oRect,"bf_bCopyIcons",
72 BF_DictAt(BF_DICT_FILES_MKSHLINK_SETICONS),true,
73 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE));
74
75 poDialog->AddOkCancelMenu(oRect);
76
77 poDialog->SetHeightFromLastChild();
78 poDialog->MoveToCenter( poWinView );
79 BF_GUI_Func_AddChildToMainView ( poDialog );
80 }
81 }
82
83 void BF_GUI_FilesPanel::Action_MakeSH_Run(BMessage *po_Message)
84 {
85 Debug_Info("!!!");
86 ASSERT(po_Message);
87
88 BL_String sTargetPath,sScriptName,sStorePath,sArgs;
89
90 if( B_OK!=sStorePath.GetFromMessage(po_Message,"bf_cStorePath") ||
91 B_OK!=sScriptName.GetFromMessage(po_Message,"bf_cScriptName") ||
92 B_OK!=sTargetPath.GetFromMessage(po_Message,"bf_cTargetPath")
93 )
94 {
95 BF_GUI_Func_PanelsEnable(true);
96 MakeFocus();
97 return;
98 }
99 sArgs.GetFromMessage(po_Message,"bf_cArgs");
100 bool bCopyIcons=true;
101 if(B_OK!=po_Message->FindBool("bf_bCopyIcons",&bCopyIcons)) bCopyIcons=true;
102
103
104 BDirectory oDir(sStorePath.String());
105 status_t uRes = oDir.InitCheck();
106 if(uRes!=B_OK){
107 BL_String sError;
108 if(B_ENTRY_NOT_FOUND==uRes) sError=BF_DictAt(BF_DICT_FILES_MKSH_ERROR2); else BL_System_TranslError(uRes,sError);
109 BF_Dialog_Alert_Sep(BF_DictAt(BF_DICT_FILES_MKSH_ERROR1),sError.String(),NULL,this);
110 return;
111 }
112
113 BL_File oFile(&oDir,sScriptName.String(),B_WRITE_ONLY|B_CREATE_FILE|B_FAIL_IF_EXISTS);
114 uRes = oFile.InitCheck();
115 if(B_OK!=uRes){
116 BL_String sError;
117 switch(uRes){
118 case B_FILE_EXISTS:
119 sError = BF_DictAt(BF_DICT_FILES_MKSH_ERROR3);
120 break;
121 case B_PERMISSION_DENIED:
122 sError = BF_DictAt(BF_DICT_FILES_MKSH_ERROR4);
123 break;
124 default:
125 BL_System_TranslError(uRes,sError);
126 }
127 BF_Dialog_Alert_Sep(BF_DictAt(BF_DICT_FILES_MKSH_ERROR5),sError.String(),NULL,this);
128 return;
129 }
130
131
132 oFile.WriteString("#!/bin/sh");
133
134
135 BL_String sData(sTargetPath);
136 if(sArgs!=""){
137 sData<<" ";
138 sData<<sArgs;
139 }
140 oFile.WriteString(sData);
141
142
143 mode_t uPerms = 0;
144 oFile.GetPermissions(&uPerms);
145 oFile.SetPermissions(uPerms|S_IXUSR);
146
147
148 if(bCopyIcons){
149 BL_File oFileSrc(sTargetPath.String(),B_READ_ONLY);
150 if(B_OK==oFileSrc.InitCheck()){
151 oFile.CopyAttributeFrom("BEOS:M:STD_ICON",oFileSrc);
152 oFile.CopyAttributeFrom("BEOS:L:STD_ICON",oFileSrc);
153 }
154 }
155
156
157 oFile.Unset();
158
159 BF_GUI_Func_PanelsEnable(true);
160 MakeFocus();
161 }
162
163