Guest User

modifyStrings.pas

a guest
Sep 21st, 2016
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 12.96 KB | None | 0 0
  1. {
  2.     Name: Perpetually Modified Strings
  3.     Author: eventHandler
  4.     Version: beta1
  5.  
  6.     Written in DelphiScript, which is an OLE scripting language dervied from Standard Pascal.
  7.     See https://support.smartbear.com/viewarticle/71968/ for more on this obscure language.
  8.  
  9.     The GUI is based on syntax learned by examining "Asset brower.pas" included with XEdit 3.1.3.
  10.     Reference sources include:
  11.         http://www.creationkit.com/index.php?title=TES5Edit_Scripting_Functions
  12.  
  13.     Mods be free!
  14.  
  15.     Hotkey: Ctrl+M
  16. }
  17. unit aaa_modifyBulkStrings;
  18.  
  19. var
  20. elBase, elName: IInterface;
  21. frm: TForm;
  22. btnAppend, btnTrim, btnReplace, btnFront2Tail, btnTail2Front, btnClose: TButton;
  23. lblNote1, lblNote2: TLabel;
  24. strAdd, strCur, strDel, strEl: string;
  25.  
  26. edClipboard: TEdit;
  27. mInfo: TMemo;
  28. cmbContainer: TComboBox;
  29.  
  30. //=====
  31.  
  32. function Process(e: IInterface): integer;
  33. begin
  34.     elBase := e;
  35.  
  36.     ShowBrowser;
  37.  
  38.     Result := 0;
  39.     Exit
  40. end;
  41.  
  42. //===== Front2Tail, Tail2Front
  43. {
  44.  
  45. }
  46.  
  47. function Front2Tail: integer;
  48. begin
  49.     Result := 0;
  50.  
  51.     if not InputQuery('Continue', 'Type here what to add to the tail:', strAdd) then begin
  52.         Result := 1;
  53.         Exit;
  54.     end;
  55.  
  56.     if not InputQuery('Done', 'Type here what to remove from the front:', strDel) then begin
  57.         Result := 2;
  58.         Exit;
  59.     end;
  60.  
  61.     if Assigned(elName) then begin
  62.     strCur := GetEditValue(elName);
  63.     Delete(strCur, 1, Length(strDel));
  64.     SetEditValue(elName, strCur + strAdd)
  65.     end;
  66. end;
  67.  
  68. //=
  69.  
  70. function Tail2Front: integer;
  71. begin
  72.     Result := 0;
  73.  
  74.     if not InputQuery('Continue', 'Type here what to add to the front:', strAdd) then begin
  75.         Result := 1;
  76.         Exit;
  77.     end;
  78.  
  79.     if not InputQuery('Done', 'Type here what to remove from the tail: ', strDel) then begin
  80.         Result := 2;
  81.         Exit;
  82.     end;
  83.  
  84.     if Assigned(elName) then begin
  85.     strCur := GetEditValue(elName);
  86.     Delete(strCur, Length(strCur) - Length(strDel) + 1, Length(strCur));
  87.     SetEditValue(elName, strAdd + strCur)
  88.     end;
  89. end;
  90.  
  91. //===== AppendFront, AppendTail
  92. {
  93.  
  94. }
  95.  
  96. function AppendFront: integer;
  97. begin
  98.     Result := 0;
  99.  
  100.     if not InputQuery('Done', 'Type here what to add to the front:', strAdd) then begin
  101.         Result := 1;
  102.         Exit
  103.     end;
  104.  
  105.     if Assigned(elName) then begin
  106.         strCur := GetEditValue(elName);
  107.         SetEditValue(elName, strAdd + strCur)
  108.     end;
  109. end;
  110.  
  111. //=
  112.  
  113. function AppendTail: integer;
  114. begin
  115.     Result := 0;
  116.  
  117.     if not InputQuery('Done', 'Type here what to add to the tail:', strAdd) then begin
  118.         Result := 2;
  119.         Exit
  120.     end;
  121.  
  122.     if Assigned(elName) then begin
  123.         strCur := GetEditValue(elName);
  124.         SetEditValue(elName, strCur + strAdd)
  125.     end;
  126. end;
  127.  
  128. //===== TrimFront, TrimTail
  129. {
  130.  
  131. }
  132.  
  133. function TrimFront: integer;
  134. begin
  135.     Result := 0;
  136.  
  137.     if not InputQuery('Continue', 'Type here what to remove from the front:', strDel) then begin
  138.         Result := 1;
  139.         Exit
  140.     end;
  141.  
  142.     if Assigned(elName) then begin
  143.         strCur := GetEditValue(elName);
  144.         Delete(strCur, 1, Length(strDel));
  145.         SetEditValue(elName, strCur)
  146.     end;
  147. end;
  148.  
  149. //=
  150.  
  151. function TrimTail: integer;
  152. begin
  153.     Result := 0;
  154.  
  155.     if not InputQuery('Continue', 'Type here what to remove from the tail:', strDel) then begin
  156.         Result := 1;
  157.         Exit
  158.     end;
  159.  
  160.     if Assigned(elName) then begin
  161.         strCur := GetEditValue(elName);
  162.         Delete(strCur, Length(strCur) - Length(strDel) + 1, Length(strCur));
  163.         SetEditValue(elName, strCur)
  164.     end;
  165. end;
  166.  
  167. //===== ReplaceAll, ReplaceFront, ReplaceTail
  168. {
  169.  
  170. }
  171.  
  172. function ReplaceAll: integer;
  173. begin
  174.     Result := 0;
  175.  
  176.     if not InputQuery('Done', 'Type here what to set as the replacement text:', strAdd) then begin
  177.         Result := 1;
  178.         Exit
  179.     end;
  180.  
  181.     if Assigned(elName) then begin
  182.         SetEditValue(elName, strAdd)
  183.     end;
  184. end;
  185.  
  186. function ReplaceFront: integer;
  187. begin
  188.     Result := 0;
  189.  
  190.     if not InputQuery('Continue', 'Type here what to remove from the front:', strDel) then begin
  191.         Result := 1;
  192.         Exit
  193.     end;
  194.  
  195.     if not InputQuery('Done', 'Type here what to add to the front:', strAdd) then begin
  196.         Result := 1;
  197.         Exit
  198.     end;
  199.  
  200.     if Assigned(elName) then begin
  201.         strCur := GetEditValue(elName);
  202.         Delete(strCur, 1, Length(strDel));
  203.         SetEditValue(elName, strAdd + strCur)
  204.     end;
  205. end;
  206.  
  207. //=
  208.  
  209. function ReplaceTail: integer;
  210. begin
  211.     Result := 0;
  212.  
  213.     if not InputQuery('Continue', 'Type here what to remove from the tail:', strDel) then begin
  214.         Result := 1;
  215.         Exit
  216.     end;
  217.  
  218.     if not InputQuery('Done', 'Type here what to add to the tail:', strAdd) then begin
  219.         Result := 2;
  220.         Exit
  221.     end;
  222.  
  223.     if Assigned(elName) then begin
  224.         strCur := GetEditValue(elName);
  225.         Delete(strCur, Length(strCur) - Length(strDel) + 1, Length(strCur));
  226.         SetEditValue(elName, strCur + strAdd)
  227.     end;
  228. end;
  229.  
  230. //===========================================================================
  231.  
  232. // on key down event handler for form
  233. procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  234. begin
  235.     if Key = VK_ESCAPE then
  236.         TForm(Sender).ModalResult := mrOk;
  237. end;
  238.  
  239. //===========================================================================
  240. procedure evtClickBtnAppend(Sender: TObject);
  241. var
  242.     strIn: string;
  243. begin
  244.     if not InputQuery('Continue', 'Type the part to perform append on (front, tail, prefix, postfix):', strIn) then begin
  245.         AddMessage('Invalid input while collecting append details.');
  246.         Exit
  247.     end;
  248.  
  249.     if (AnsiCompareText(strIn, 'front') = 0) or (AnsiCompareText(strIn, 'prefix') = 0) then begin
  250.         AppendFront;
  251.         Exit
  252.     end;
  253.  
  254.     if (AnsiCompareText(strIn, 'tail') = 0) or (AnsiCompareText(strIn, 'postfix') = 0) then begin
  255.         AppendTail;
  256.         Exit
  257.     end;
  258.  
  259.     AddMessage('evtClickBtnAppend error: invalid input.');
  260. end;
  261.  
  262. //===
  263.  
  264. procedure evtClickBtnTrim(Sender: TObject);
  265. var
  266.     strIn: string;
  267. begin
  268.     if not InputQuery('Continue', 'Type the part to perform trim on (front, tail, prefix, postfix):', strIn) then begin
  269.         AddMessage('Invalid input while collecting trim details.');
  270.         Exit
  271.     end;
  272.  
  273.     if (AnsiCompareText(strIn, 'front') = 0) or (AnsiCompareText(strIn, 'prefix') = 0) then begin
  274.         TrimFront;
  275.         Exit
  276.     end;
  277.     if (AnsiCompareText(strIn, 'tail') = 0) or (AnsiCompareText(strIn, 'postfix') = 0) then begin
  278.         TrimTail;
  279.         Exit
  280.     end;
  281.  
  282.     AddMessage('evtClickBtnTrim error: invalid input.');
  283. end;
  284.  
  285. //===
  286.  
  287. procedure evtClickBtnReplace(Sender: TObject);
  288. var
  289.     strIn: string;
  290. begin
  291.     if not InputQuery('Continue', 'Type the part to perform replacement on (all, front, tail, prefix, postfix):', strIn) then begin
  292.         AddMessage('Invalid input while collecting replacement details.');
  293.         Exit
  294.     end;
  295.  
  296.     if (AnsiCompareText(strIn, 'all') = 0) then begin
  297.         ReplaceAll;
  298.         Exit
  299.     end;
  300.     if (AnsiCompareText(strIn, 'front') = 0) or (AnsiCompareText(strIn, 'prefix') = 0) then begin
  301.         ReplaceFront;
  302.         Exit
  303.     end;
  304.     if (AnsiCompareText(strIn, 'tail') = 0) or (AnsiCompareText(strIn, 'postfix') = 0) then begin
  305.         ReplaceTail;
  306.         Exit
  307.     end;
  308.  
  309.     AddMessage('evtClickBtnReplace error: invalid input.');
  310. end;
  311.  
  312. //===
  313.  
  314. procedure evtClickBtnFront2Tail(Sender: TObject);
  315. begin
  316.     Front2Tail;
  317.     AddMessage('evtClickBtnFront2Tail running.');
  318. end;
  319.  
  320. //===
  321.  
  322. procedure evtClickBtnTail2Front(Sender: TObject);
  323. begin
  324.     Tail2Front;
  325.     AddMessage('evtClickBtnTail2Front running.');
  326. end;
  327.  
  328. //===
  329.  
  330. procedure cmbContainerOnChange(Sender: TObject);
  331. begin
  332.     strEl := cmbContainer.Text;
  333.     AddMessage('element string:' + strEl);
  334.     elName := ElementByName(elBase, strEl);
  335. end;
  336.  
  337. //===
  338.  
  339. procedure ShowBrowser;
  340. var
  341.     i, tOff, lOff, vPad, hPad, btnWidth: integer;
  342. begin
  343.     tOff := 48;
  344.     lOff := 24;
  345.     vPad := 8;
  346.     hPad := 8;
  347.     btnWidth := 180;
  348.     frm := TForm.Create(nil);
  349.     try
  350.         frm.Caption := 'Perpetually Modified Strings';
  351.         frm.Width := 900;
  352.         frm.Height := 480;
  353.         frm.Position := poScreenCenter;
  354.         frm.KeyPreview := True;
  355.         frm.OnKeyDown := FormKeyDown;
  356.  
  357.         btnAppend := TButton.Create(frm);
  358.         btnAppend.Parent := frm;
  359.         btnAppend.Top := tOff;
  360.         btnAppend.Left := lOff;
  361.         btnAppend.Width := btnWidth;
  362.         btnAppend.Caption := 'Append to existing entry.';
  363.         btnAppend.Anchors := [akRight, akBottom];
  364.         btnAppend.OnClick := evtClickBtnAppend;
  365.  
  366.         btnTrim := TButton.Create(frm);
  367.         btnTrim.Parent := frm;
  368.         btnTrim.Top := btnAppend.Top + btnAppend.Height + vPad;
  369.         btnTrim.Left := lOff;
  370.         btnTrim.Width := btnWidth;
  371.         btnTrim.Caption := 'Trim from existing entry.';
  372.         btnTrim.Anchors := [akRight, akBottom];
  373.         btnTrim.OnClick := evtClickBtnTrim;
  374.  
  375.         btnReplace := TButton.Create(frm);
  376.         btnReplace.Parent := frm;
  377.         btnReplace.Top := btnTrim.Top + btnTrim.Height + vPad;
  378.         btnReplace.Left := lOff;
  379.         btnReplace.Width := btnWidth;
  380.         btnReplace.Caption := 'Replace part/all of existing entry.';
  381.         btnReplace.Anchors := [akRight, akBottom];
  382.         btnReplace.OnClick := evtClickBtnReplace;
  383.  
  384.         btnFront2Tail := TButton.Create(frm);
  385.         btnFront2Tail.Parent := frm;
  386.         btnFront2Tail.Top := tOff;
  387.         btnFront2Tail.Left := lOff + btnWidth + hPad;
  388.         btnFront2Tail.Width := btnWidth;
  389.         btnFront2Tail.Caption := 'Front2Tail';
  390.         btnFront2Tail.Anchors := [akRight, akBottom];
  391.         btnFront2Tail.OnClick := evtClickBtnFront2Tail;
  392.  
  393.         btnTail2Front := TButton.Create(frm);
  394.         btnTail2Front.Parent := frm;
  395.         btnTail2Front.Top := btnFront2Tail.Top + btnFront2Tail.Height + vPad;
  396.         btnTail2Front.Left := lOff + btnWidth + hPad;
  397.         btnTail2Front.Width := btnWidth;
  398.         btnTail2Front.Caption := 'Tail2Front';
  399.         btnTail2Front.Anchors := [akRight, akBottom];
  400.         btnTail2Front.OnClick := evtClickBtnTail2Front;
  401.  
  402.         btnClose := TButton.Create(frm);
  403.         btnClose.Parent := frm;
  404.         btnClose.Top := btnReplace.Top + btnReplace.Height + vPad;
  405.         btnClose.Left := lOff;
  406.         btnClose.Width := btnWidth;
  407.         btnClose.Caption := 'Close';
  408.         btnClose.Anchors := [akRight, akBottom];
  409.         btnClose.ModalResult := mrOk;
  410.  
  411.         // invisible edit field used to copy to clipboard
  412.         edClipboard := TEdit.Create(frm);
  413.         edClipboard.Parent := frm;
  414.         edClipboard.Visible := False;
  415.  
  416.         mInfo := TMemo.Create(frm);
  417.         mInfo.Parent := frm;
  418.         mInfo.Top := btnClose.Top + btnClose.Height + vPad*8;
  419.         mInfo.Left := lOff;
  420.         mInfo.Width := frm.Width - lOff*2;
  421.         mInfo.Height := 180;
  422.         mInfo.Anchors := [akLeft, akRight, akBottom];
  423.         mInfo.ScrollBars := ssVertical;
  424.         mInfo.ReadOnly := True;
  425.  
  426.         lblNote1 := TLabel.Create(frm);
  427.         lblNote1.Parent := frm;
  428.         lblNote1.Top := mInfo.Top + mInfo.Height + vPad;
  429.         lblNote1.Left := lOff + btnWidth/2;
  430.         lblNote1.Anchors := [akRight, akBottom];
  431.         lblNote1.Caption := 'Note: Replace front/tail only replaces the same # of characters used as input,'#13'      it does NOT actually compare the front/tail to the input being replaced.';
  432.  
  433.         cmbContainer := TComboBox.Create(frm);
  434.         cmbContainer.Parent := frm;
  435.         cmbContainer.Top := tOff/6;
  436.         cmbContainer.Left := frm.Width/2 + btnWidth;
  437.         cmbContainer.Width := frm.Width - cmbContainer.Left - lOff;
  438.         cmbContainer.Style := csDropDownList;
  439.         cmbContainer.DropDownCount := 16;
  440.         cmbContainer.Anchors := [akTop, akRight];
  441.         cmbContainer.OnChange := cmbContainerOnChange;
  442.         cmbContainer.Items.Add('EDID - Editor ID');
  443.         cmbContainer.Items.Add('FULL - Name');
  444.         cmbContainer.Items.Add('DESC - Description');
  445.         cmbContainer.Items.Add('CNAM - Created Object');
  446.         cmbContainer.Items.Add('BNAM - Workbench Keyword');
  447.         cmbContainer.Items.Add('YNAM - Sound - Pick Up');
  448.         cmbContainer.Items.Add('ZNAM - Sound - Drop');
  449.         cmbContainer.Items.Add('CRIF - Crime faction');
  450.         cmbContainer.Items.Add('DOFT - Default outfit');
  451.         cmbContainer.Items.Add('RNAM - Race');
  452.         cmbContainer.Items.Add('CNAM - Class');
  453.         cmbContainer.Items.Add('ATKR - Attack Race');
  454.         cmbContainer.Items.Add('ZNAM - Combat Style');
  455.         cmbContainer.Items.Add('HCLF - Hair Color');
  456.         cmbContainer.Items.Add('FTST - Head texture');
  457.         cmbContainer.Items.Add('VTCK - Voice');
  458.         //for i := 0 to Pred(slContainers.Count) do
  459.         //  cmbContainer.Items.Add(SimpleName(slContainers[i]));
  460.         cmbContainer.ItemIndex := 0;
  461.  
  462.         lblNote2 := TLabel.Create(frm);
  463.         lblNote2.Parent := frm;
  464.         lblNote2.Top := cmbContainer.Top + cmbContainer.Height + vPad;
  465.         lblNote2.Left := cmbContainer.Left;
  466.         lblNote2.Anchors := [akRight, akBottom];
  467.         lblNote2.Caption := 'WARNING: Currently no safeguards to ensure'#13'the records being modified have the selected field'#13'from this drop down list! It is YOUR responsibility'#13'to pick valid options for the records being modified.';
  468.  
  469.         strEl := cmbContainer.Text;
  470.         AddMessage('element string:' + strEl);
  471.         elName := ElementByName(elBase, strEl);
  472.  
  473.         frm.ShowModal;
  474.     finally
  475.         frm.Free;
  476.     end;
  477. end;
  478.  
  479. //===========================================================================
  480. {
  481. function Initialize: integer;
  482. begin
  483.     Result := 1;
  484. end;
  485. }
  486. //===========================================================================
  487.  
  488. {
  489.     Always use tabs when indenting, and remember: Only YOU can prevent chaotic text alignment with untold bytes wasted on white space!
  490.  
  491.     Use Notepad++ and choose your own tab width for personal preference! Standard tab width is four fixed-width spaces. That is the only correct width, and what any civilized person will use.
  492.  
  493.     I take full (posthumous) responsibility if you blow up the planet using my scripts, but not for more mundane annoyances. I apologize in advance to everyone affected by the world blowing up.
  494.  
  495.     No lawsuits allowed against me. You've been warned!
  496. }
  497.  
  498. end.
Advertisement
Add Comment
Please, Sign In to add comment