-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
871 lines (692 loc) · 38.2 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
Imports System.IO
Public Class Form1
Private WithEvents infoToolTip As New ToolTip()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Load the saved value for Template Location
TextBox_Template_Location.Text = My.Settings.TemplateLocation
TextBox_CLIHome.Text = My.Settings.CLIInstallLocation
ComboBox_Background_Template.Text = My.Settings.Setting_Background
ComboBox_Monster_Template.Text = My.Settings.Setting_Monster
ComboBox_Item_Template.Text = My.Settings.Setting_Item
ComboBox_Template_Race.Text = My.Settings.Setting_Race
ComboBox_Spell_Template.Text = My.Settings.Setting_Spell
TextBox_From.Text = My.Settings.Setting_From
TextBox_Adventure.Text = My.Settings.Setting_Adventure
TextBox_Book.Text = My.Settings.Setting_Book
TextBox_Config_File.Text = My.Settings.Setting_JSON
TextBox_Data_Folder.Text = My.Settings.Setting_DataFolder
TextBox_ImageFolder.Text = My.Settings.Setting_ImageFolder
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub UpdateTemplateRootPath()
' Private subroutine to update TextBox_Template_Root
' Get the absolute paths from settings
Dim cliInstallPath As String = My.Settings.CLIInstallLocation
Dim templatePath As String = My.Settings.TemplateLocation
' Remove the CLIInstallLocation part from the TemplateLocation path to get the relative part
Dim relativePath As String = templatePath.Replace(cliInstallPath, "")
' Remove leading backslash (if any) from the relative path
relativePath = relativePath.TrimStart("\"c)
' Replace all backslashes with forward slashes
relativePath = relativePath.Replace("\"c, "/"c)
' Store the calculated relative path in My.Settings.Setting_RelativeTemplatePath
My.Settings.Setting_RelativeTemplatePath = relativePath
End Sub
Private Sub BuildConfigFile()
' Initialize the configText variable
Dim configText As String = "{"
' "from" section
configText &= vbCrLf & " ""from"" : ["
If Not String.IsNullOrEmpty(My.Settings.Setting_From) Then
Dim fromArray = My.Settings.Setting_From.Split(","c).Select(Function(item) """" & item.Trim() & """")
configText &= vbCrLf & " " & String.Join("," & vbCrLf & " ", fromArray)
End If
configText &= vbCrLf & " ],"
' "paths" section
configText &= vbCrLf & " ""paths"" : {"
configText &= vbCrLf & " ""compendium"" : """ & My.Settings.Setting_Compendium & "/3-Mechanics/CLI/"","
configText &= vbCrLf & " ""rules"" : """ & My.Settings.Setting_Rules & "/3-Mechanics/CLI/rules/"""
configText &= vbCrLf & " },"
' "template" section
configText &= vbCrLf & " ""template"" : {"
configText &= vbCrLf & " ""background"" : """ & My.Settings.Setting_RelativeTemplatePath & "/" & My.Settings.Setting_Background & ""","
configText &= vbCrLf & " ""monster"" : """ & My.Settings.Setting_RelativeTemplatePath & "/" & My.Settings.Setting_Monster & ""","
configText &= vbCrLf & " ""item"" : """ & My.Settings.Setting_RelativeTemplatePath & "/" & My.Settings.Setting_Item & ""","
configText &= vbCrLf & " ""race"" : """ & My.Settings.Setting_RelativeTemplatePath & "/" & My.Settings.Setting_Race & ""","
configText &= vbCrLf & " ""spell"" : """ & My.Settings.Setting_RelativeTemplatePath & "/" & My.Settings.Setting_Spell & """"
configText &= vbCrLf & " },"
' "useDiceRoller" section
configText &= vbCrLf & " ""useDiceRoller"" : " & If(CheckBox_DiceRoller.Checked, "true", "false") & ","
' "tagPrefix" section
configText &= vbCrLf & " ""tagPrefix"" : """ & TextBox_tagPrefix.Text & ""","
' "yamlStatblocks" section
configText &= vbCrLf & " ""yamlStatblocks"" : true,"
' "images" section
configText &= vbCrLf & " ""images"" : {"
configText &= vbCrLf & " ""copyExternal"" : " & If(CheckBox_Img_External.Checked, "true", "false") & ","
configText &= vbCrLf & " ""copyInternal"" : " & If(CheckBox_Img_Internal.Checked, "true", "false") & ","
configText &= vbCrLf & " ""internalRoot"" : ""5etools-img"""
configText &= vbCrLf & " },"
' "full-source" section
configText &= vbCrLf & " ""full-source"" : {"
' "adventure" section
configText &= vbCrLf & " ""adventure"" : ["
If Not String.IsNullOrEmpty(My.Settings.Setting_Adventure) Then
Dim adventureArray = My.Settings.Setting_Adventure.Split(","c).Select(Function(item) """" & item.Trim() & """")
configText &= vbCrLf & " " & String.Join("," & vbCrLf & " ", adventureArray)
End If
configText &= vbCrLf & " ],"
' "book" section
configText &= vbCrLf & " ""book"" : ["
If Not String.IsNullOrEmpty(My.Settings.Setting_Book) Then
Dim bookArray = My.Settings.Setting_Book.Split(","c).Select(Function(item) """" & item.Trim() & """")
configText &= vbCrLf & " " & String.Join("," & vbCrLf & " ", bookArray)
End If
configText &= vbCrLf & " ]"
configText &= vbCrLf & " }"
configText &= vbCrLf & "}"
' Assign the text to the TextBox
TextBox_ConfigFile_Build.Text = configText
End Sub
Private Sub UpdateSpellTemplateList()
' Clear existing items in the ComboBox
ComboBox_Spell_Template.Items.Clear()
' Get the location from TextBox_Template_Location
Dim templateLocation As String = TextBox_Template_Location.Text
' Ensure the directory exists
If Directory.Exists(templateLocation) Then
' Get all *.txt files containing "spell" in the name
Dim spellFiles = Directory.GetFiles(templateLocation, "*.txt").
Where(Function(f) f.ToLower().Contains("spell")).ToArray()
' Add these files to the ComboBox
For Each file As String In spellFiles
ComboBox_Spell_Template.Items.Add(Path.GetFileName(file))
Next
End If
End Sub
Private Sub UpdateRaceTemplateList()
' Clear existing items in the ComboBox
ComboBox_Template_Race.Items.Clear()
' Get the location from TextBox_Template_Location
Dim templateLocation As String = TextBox_Template_Location.Text
' Ensure the directory exists
If Directory.Exists(templateLocation) Then
' Get all *.txt files containing "race" in the name
Dim raceFiles = Directory.GetFiles(templateLocation, "*.txt").
Where(Function(f) f.ToLower().Contains("race")).ToArray()
' Add these files to the ComboBox
For Each file As String In raceFiles
ComboBox_Template_Race.Items.Add(Path.GetFileName(file))
Next
End If
End Sub
Private Sub UpdateItemTemplateList()
' Clear existing items in the ComboBox
ComboBox_Item_Template.Items.Clear()
' Get the location from TextBox_Template_Location
Dim templateLocation As String = TextBox_Template_Location.Text
' Ensure the directory exists
If Directory.Exists(templateLocation) Then
' Get all *.txt files containing "item" in the name
Dim itemFiles = Directory.GetFiles(templateLocation, "*.txt").
Where(Function(f) f.ToLower().Contains("item")).ToArray()
' Add these files to the ComboBox
For Each file As String In itemFiles
ComboBox_Item_Template.Items.Add(Path.GetFileName(file))
Next
End If
End Sub
Private Sub UpdateBackgroundTemplateList()
' Clear existing items in the ComboBox
ComboBox_Background_Template.Items.Clear()
' Get the location from TextBox_Template_Location
Dim templateLocation As String = TextBox_Template_Location.Text
' Ensure the directory exists
If Directory.Exists(templateLocation) Then
' Get all *.txt files containing "background" in the name
Dim backgroundFiles = Directory.GetFiles(templateLocation, "*.txt").
Where(Function(f) f.ToLower().Contains("background")).ToArray()
' Add these files to the ComboBox
For Each file As String In backgroundFiles
ComboBox_Background_Template.Items.Add(Path.GetFileName(file))
Next
End If
End Sub
Private Sub Button_Folder_Browse_Click(sender As Object, e As EventArgs)
' Create a new instance of FolderBrowserDialog
Using folderDialog As New FolderBrowserDialog
' Optional: Set the description displayed in the dialog
folderDialog.Description = "Select a folder for the CLI source path."
' Optional: Set the root folder (e.g., Desktop or My Computer)
folderDialog.RootFolder = Environment.SpecialFolder.Desktop
' Show the dialog and check if the user selected a folder
If folderDialog.ShowDialog = DialogResult.OK Then
' Copy the selected folder path to CLI_Source
CLI_Source.Text = folderDialog.SelectedPath
End If
End Using
End Sub
Private Sub Button_Config_File_Click(sender As Object, e As EventArgs)
' Create a new instance of OpenFileDialog
Using openFileDialog As New OpenFileDialog
' Set the filter to show only .json files
openFileDialog.Filter = "JSON Files (*.json)|*.json"
openFileDialog.Title = "Select a Configuration File"
' Show the dialog and check if the user selected a file
If openFileDialog.ShowDialog = DialogResult.OK Then
' Get only the file name and update TextBox_Config_File
TextBox_Config_File.Text = IO.Path.GetFileName(openFileDialog.FileName)
End If
End Using
End Sub
Private Sub Label5_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Button_Data_Folder_Click(sender As Object, e As EventArgs)
' Ensure CLI_Source is populated
If String.IsNullOrWhiteSpace(CLI_Source.Text) Then
MessageBox.Show("Please select or specify a folder in CLI_Source first.", "Warning")
Return
End If
' Get the CLI_Source path
Dim basePath = CLI_Source.Text
' Validate that the CLI_Source path exists
If Not IO.Directory.Exists(basePath) Then
MessageBox.Show("The folder specified in CLI_Source does not exist.", "Error")
Return
End If
' Create a FolderBrowserDialog to select a folder
Using folderDialog As New FolderBrowserDialog
folderDialog.Description = "Select a data folder."
folderDialog.RootFolder = Environment.SpecialFolder.Desktop
' Show the dialog and check if a folder was selected
If folderDialog.ShowDialog = DialogResult.OK Then
Dim selectedPath = folderDialog.SelectedPath
' Check if the selected path starts with the base path
If selectedPath.StartsWith(basePath, StringComparison.OrdinalIgnoreCase) Then
' Calculate the relative path
Dim relativePath = selectedPath.Substring(basePath.Length).TrimStart(IO.Path.DirectorySeparatorChar)
TextBox_Data_Folder.Text = relativePath
Else
MessageBox.Show("The selected folder is not within the folder specified in CLI_Source.", "Error")
End If
End If
End Using
End Sub
' Event Handler for when the value in TextBox_OutputFolder changes
Private Sub TextBox_OutputFolder_TextChanged(sender As Object, e As EventArgs) Handles TextBox_OutputFolder.TextChanged
UpdateCommandText()
End Sub
' Event Handler for when the value in TextBox_Config_File changes
Private Sub TextBox_Config_File_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Config_File.TextChanged
UpdateCommandText()
' Save the new value to settings
My.Settings.Setting_Config = TextBox_Config_File.Text
My.Settings.Save()
End Sub
' Event Handler for when the value in TextBox_Data_Folder changes
Private Sub TextBox_Data_Folder_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Data_Folder.TextChanged
UpdateCommandText()
' Save the new value to settings
My.Settings.Setting_DataFolder = TextBox_Data_Folder.Text
My.Settings.Save()
End Sub
' Event Handler for when the checkbox is checked or unchecked
Private Sub CheckBoxIndex_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBoxIndex.CheckedChanged
UpdateCommandText()
End Sub
' Event Handler for when the CLI_Source path changes
Private Sub CLI_Source_TextChanged(sender As Object, e As EventArgs) Handles CLI_Source.TextChanged
UpdateCommandText()
End Sub
' Function to update the command in TextBox_Command dynamically
Private Sub UpdateCommandText()
' Construct the base command with the executable
Dim command As String = "ttrpg-convert.exe"
' Include the --index flag if CheckBoxIndex is checked
If CheckBoxIndex.Checked Then
command &= " --index"
End If
' Add the output folder (-o)
If Not String.IsNullOrEmpty(TextBox_OutputFolder.Text) Then
command &= " -o """ & TextBox_OutputFolder.Text & """"
End If
' Add the config file (-c)
If Not String.IsNullOrEmpty(TextBox_Config_File.Text) Then
command &= " -c """ & TextBox_Config_File.Text & """"
End If
' Add the data folder (folder to process)
If Not String.IsNullOrEmpty(TextBox_Data_Folder.Text) Then
command &= " """ & TextBox_Data_Folder.Text & """"
End If
' Update the TextBox_Command with the new constructed command
TextBox_Command.Text = command
End Sub
' Event Handler for the Button_SelectCLIHome click event
Private Sub TabPage3_Click(sender As Object, e As EventArgs) Handles TabPage_RunCLI.Click
End Sub
Private Sub Button_InstallGit_Click(sender As Object, e As EventArgs) Handles Button_InstallGit.Click
' URL of the Git website
Dim gitUrl As String = "https://git-scm.com/"
' Use ProcessStartInfo to open the URL in the default browser
Try
Dim processStartInfo As New ProcessStartInfo(gitUrl)
processStartInfo.UseShellExecute = True
Process.Start(processStartInfo)
Catch ex As Exception
MessageBox.Show($"Failed to open the website: {ex.Message}", "Error")
End Try
End Sub
Private Sub Button_SelectCLIHome_Click(sender As Object, e As EventArgs) Handles Button_SelectCLIHome.Click
' Create a new instance of FolderBrowserDialog
Using folderDialog As New FolderBrowserDialog
' Optional: Set the description displayed in the dialog
folderDialog.Description = "Select the CLI home folder."
' Optional: Set the root folder (e.g., Desktop or My Computer)
folderDialog.RootFolder = Environment.SpecialFolder.Desktop
' Show the dialog and check if the user selected a folder
If folderDialog.ShowDialog = DialogResult.OK Then
' Copy the selected folder path to TextBox_CLIHome
TextBox_CLIHome.Text = folderDialog.SelectedPath
End If
End Using
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
' URL of the CLI website
Dim gitUrl2 As String = "https://github.com/ebullient/ttrpg-convert-cli/releases"
' Use ProcessStartInfo to open the URL in the default browser
Try
Dim processStartInfo As New ProcessStartInfo(gitUrl2)
processStartInfo.UseShellExecute = True
Process.Start(processStartInfo)
Catch ex As Exception
MessageBox.Show($"Failed to open the website: {ex.Message}", "Error")
End Try
End Sub
Private Sub Button_Folder_Browse_Click_1(sender As Object, e As EventArgs) Handles Button_Folder_Browse.Click
' Create a new instance of FolderBrowserDialog
Using folderDialog As New FolderBrowserDialog
' Optional: Set the description displayed in the dialog
folderDialog.Description = "Select a folder for the CLI source path."
' Optional: Set the root folder (e.g., Desktop or My Computer)
folderDialog.RootFolder = Environment.SpecialFolder.Desktop
' Show the dialog and check if the user selected a folder
If folderDialog.ShowDialog = DialogResult.OK Then
' Copy the selected folder path to CLI_Source
CLI_Source.Text = folderDialog.SelectedPath
End If
End Using
End Sub
Private Sub Button_Config_File_Click_1(sender As Object, e As EventArgs) Handles Button_Config_File.Click
' Create a new instance of OpenFileDialog
Using openFileDialog As New OpenFileDialog
' Set the filter to show only .json files
openFileDialog.Filter = "JSON Files (*.json)|*.json"
openFileDialog.Title = "Select a Configuration File"
' Show the dialog and check if the user selected a file
If openFileDialog.ShowDialog = DialogResult.OK Then
' Get only the file name and update TextBox_Config_File
TextBox_Config_File.Text = IO.Path.GetFileName(openFileDialog.FileName)
End If
End Using
End Sub
Private Sub Button_Data_Folder_Click_1(sender As Object, e As EventArgs) Handles Button_Data_Folder.Click
' Ensure CLI_Source is populated
If String.IsNullOrWhiteSpace(CLI_Source.Text) Then
MessageBox.Show("Please select or specify a folder in CLI_Source first.", "Warning")
Return
End If
' Get the CLI_Source path
Dim basePath = CLI_Source.Text
' Validate that the CLI_Source path exists
If Not IO.Directory.Exists(basePath) Then
MessageBox.Show("The folder specified in CLI_Source does not exist.", "Error")
Return
End If
' Create a FolderBrowserDialog to select a folder
Using folderDialog As New FolderBrowserDialog
folderDialog.Description = "Select a data folder."
folderDialog.RootFolder = Environment.SpecialFolder.Desktop
' Show the dialog and check if a folder was selected
If folderDialog.ShowDialog = DialogResult.OK Then
Dim selectedPath = folderDialog.SelectedPath
' Check if the selected path starts with the base path
If selectedPath.StartsWith(basePath, StringComparison.OrdinalIgnoreCase) Then
' Calculate the relative path
Dim relativePath = selectedPath.Substring(basePath.Length).TrimStart(IO.Path.DirectorySeparatorChar)
TextBox_Data_Folder.Text = relativePath
Else
MessageBox.Show("The selected folder is not within the folder specified in CLI_Source.", "Error")
End If
End If
End Using
End Sub
Private Sub TextBox_Command_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Command.TextChanged
End Sub
Private Sub Button_Run_CLI_Click(sender As Object, e As EventArgs) Handles Button_Run_CLI.Click
Dim command = TextBox_Command.Text ' Command to run
Dim folderPath = CLI_Source.Text ' Folder path from CLI_Source
If Not String.IsNullOrWhiteSpace(command) AndAlso Not String.IsNullOrWhiteSpace(folderPath) Then
Try
' Create a new process to run the command
Dim process As New Process
process.StartInfo.FileName = "cmd.exe"
process.StartInfo.Arguments = $"/K {command}" ' /K keeps the Command Prompt open after execution
process.StartInfo.WorkingDirectory = folderPath ' Set the starting directory
process.StartInfo.UseShellExecute = True ' Allows the window to be visible
process.StartInfo.CreateNoWindow = False ' Ensures the Command Prompt window is created
process.Start()
Catch ex As Exception
MessageBox.Show($"An error occurred: {ex.Message}", "Error")
End Try
Else
If String.IsNullOrWhiteSpace(folderPath) Then
MessageBox.Show("Please enter a valid folder path in CLI_Source.", "Warning")
End If
If String.IsNullOrWhiteSpace(command) Then
MessageBox.Show("Please enter a command in TextBox1.", "Warning")
End If
End If
End Sub
Private Sub Button_Download_SourceData_Click(sender As Object, e As EventArgs) Handles Button_Download_SourceData.Click
Dim downloadUrl As String = "https://github.com/5etools-mirror-3/5etools-src/releases/tag/v1.210.4"
Try
' Using ProcessStartInfo to open the URL
Dim processInfo As New ProcessStartInfo(downloadUrl) With {
.UseShellExecute = True
}
Process.Start(processInfo)
Catch ex As Exception
MessageBox.Show("An error occurred while trying to open the link: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim downloadUrl = "https://github.com/5etools-mirror-3/5etools-img/releases/tag/v1.210.4"
Try
' Using ProcessStartInfo to open the URL
Dim processInfo As New ProcessStartInfo(downloadUrl) With {
.UseShellExecute = True
}
Process.Start(processInfo)
Catch ex As Exception
MessageBox.Show("An error occurred while trying to open the link: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Label10_Click(sender As Object, e As EventArgs) Handles Label10.Click
End Sub
Private Sub Label12_Click(sender As Object, e As EventArgs) Handles Label12.Click
End Sub
Private Sub Label14_Click(sender As Object, e As EventArgs) Handles Label14.Click
End Sub
Private Sub Button_DL_Templates_Click(sender As Object, e As EventArgs) Handles Button_DL_Templates.Click
' Retrieve the folder path from TextBox_CLIHome
Dim cliHomePath As String = TextBox_CLIHome.Text
' Update TextBox_Template_Location
TextBox_Template_Location.Text = Path.Combine(cliHomePath, "ttrpg-convert-cli\examples\templates\tools5e")
' Proceed with downloading templates (previous code)
If Not Directory.Exists(cliHomePath) Then
MessageBox.Show("The specified CLI home folder does not exist. Please select a valid folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
Dim gitCommand As String = "git clone --depth 1 https://github.com/ebullient/ttrpg-convert-cli"
Try
Dim startInfo As New ProcessStartInfo With {
.FileName = "cmd.exe",
.WorkingDirectory = cliHomePath,
.Arguments = $"/c {gitCommand}",
.UseShellExecute = False,
.CreateNoWindow = True
}
Using process As Process = Process.Start(startInfo)
process.WaitForExit()
End Using
MessageBox.Show("Templates have been downloaded successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show($"An error occurred while running the command: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
UpdateTemplateRootPath()
End Sub
Private Sub UpdateMonsterTemplateList()
' Clear the ComboBox
ComboBox_Monster_Template.Items.Clear()
' Get the directory path from TextBox_Template_Location
Dim templateLocation As String = TextBox_Template_Location.Text
' Validate the directory exists
If Not Directory.Exists(templateLocation) Then
MessageBox.Show("The specified template location does not exist. Please provide a valid path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
' Get all .txt files containing 'monster' in the filename
Dim monsterFiles As String() = Directory.GetFiles(templateLocation, "*.txt").
Where(Function(f) f.ToLower().Contains("monster")).ToArray()
' Add files to the ComboBox
For Each file As String In monsterFiles
ComboBox_Monster_Template.Items.Add(Path.GetFileName(file))
Next
' Optionally select the first item
If ComboBox_Monster_Template.Items.Count > 0 Then
ComboBox_Monster_Template.SelectedIndex = 0
End If
End Sub
Private Sub TextBox_Template_Location_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Template_Location.TextChanged
' Save the new location to settings
My.Settings.TemplateLocation = TextBox_Template_Location.Text
My.Settings.Save()
' Update ComboBoxes
UpdateMonsterTemplateList()
UpdateBackgroundTemplateList()
UpdateItemTemplateList()
UpdateRaceTemplateList()
UpdateSpellTemplateList()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_CLIHome_TextChanged(sender As Object, e As EventArgs) Handles TextBox_CLIHome.TextChanged
' Save the new value to settings
My.Settings.CLIInstallLocation = TextBox_CLIHome.Text
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub ComboBox_Item_Template_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_Item_Template.SelectedIndexChanged
' Store the selected value in settings
My.Settings.Setting_Item = ComboBox_Item_Template.SelectedItem?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub ComboBox_Background_Template_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_Background_Template.SelectedIndexChanged
' Store the selected value in settings
My.Settings.Setting_Background = ComboBox_Background_Template.SelectedItem?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub ComboBox_Monster_Template_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_Monster_Template.SelectedIndexChanged
' Store the selected value in settings
My.Settings.Setting_Monster = ComboBox_Monster_Template.SelectedItem?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub ComboBox_Template_Race_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_Template_Race.SelectedIndexChanged
' Store the selected value in settings
My.Settings.Setting_Race = ComboBox_Template_Race.SelectedItem?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub ComboBox_Spell_Template_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_Spell_Template.SelectedIndexChanged
' Store the selected value in settings
My.Settings.Setting_Spell = ComboBox_Spell_Template.SelectedItem?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub Label15_Click(sender As Object, e As EventArgs) Handles Label15.Click
End Sub
Private Sub Form1_MaximizedBoundsChanged(sender As Object, e As EventArgs) Handles Me.MaximizedBoundsChanged
End Sub
Private Sub TextBox_Adventure_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Adventure.TextChanged
' Store the selected value in settings
My.Settings.Setting_Adventure = TextBox_Adventure.Text?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_From_TextChanged(sender As Object, e As EventArgs) Handles TextBox_From.TextChanged
' Store the selected value in settings
My.Settings.Setting_From = TextBox_From.Text?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_Book_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Book.TextChanged
' Store the selected value in settings
My.Settings.Setting_Book = TextBox_Book.Text?.ToString()
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox_ConfigFile_Build.TextChanged
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_Compendium_Location_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Compendium_Location.TextChanged
' Save the current value of TextBox_Compendium_Location to Setting_Compendium
My.Settings.Setting_Compendium = TextBox_Compendium_Location.Text
' Optionally, save settings immediately
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_Rules_Location_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Rules_Location.TextChanged
' Save the current value of TextBox_Compendium_Location to Setting_Compendium
My.Settings.Setting_Rules = TextBox_Rules_Location.Text
' Optionally, save settings immediately
My.Settings.Save()
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub CheckBox_DiceRoller_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox_DiceRoller.CheckedChanged
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub CheckBox_Img_External_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox_Img_External.CheckedChanged
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub CheckBox_Img_Internal_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox_Img_Internal.CheckedChanged
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_tagPrefix_TextChanged(sender As Object, e As EventArgs) Handles TextBox_tagPrefix.TextChanged
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_Img_Folder_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Img_Folder.TextChanged
' Call the BuildConfigFile method to generate the text for TextBox_ConfigFile_Build
BuildConfigFile()
End Sub
Private Sub TextBox_Config_Name_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Config_Name.TextChanged
' Store the selected value in settings
My.Settings.Setting_JSON = TextBox_Config_Name.Text?.ToString()
My.Settings.Save()
End Sub
Private Sub Button_Build_Json_Click(sender As Object, e As EventArgs) Handles Button_Build_Json.Click
' Call BuildConfigFile to ensure the JSON content is up to date
BuildConfigFile()
' Retrieve the file name and location
Dim fileName As String = My.Settings.Setting_JSON
Dim savePath As String = System.IO.Path.Combine(My.Settings.CLIInstallLocation, fileName)
Try
' Write the contents of TextBox_ConfigFile_Build to the JSON file
System.IO.File.WriteAllText(savePath, TextBox_ConfigFile_Build.Text)
' Notify the user of successful save
MessageBox.Show("JSON file saved successfully to: " & savePath, "Save Successful", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
' Notify the user of any errors during the save
MessageBox.Show("An error occurred while saving the file: " & ex.Message, "Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
TextBox_Config_File.Text = My.Settings.Setting_JSON
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
' Get the absolute paths from settings
Dim cliInstallPath = My.Settings.CLIInstallLocation
Dim templatePath = My.Settings.TemplateLocation
' Remove the CLIInstallLocation part from the TemplateLocation path to get the relative part
Dim relativePath = templatePath.Replace(cliInstallPath, "")
' Remove leading backslash (if any) from the relative path
relativePath = relativePath.TrimStart("\"c)
End Sub
Private Sub Label19_Click(sender As Object, e As EventArgs) Handles Label19.Click
End Sub
Private Sub Button_Image_Folder_Click(sender As Object, e As EventArgs) Handles Button_Image_Folder.Click
' Create a new instance of FolderBrowserDialog
Using folderDialog As New FolderBrowserDialog()
' Set the initial directory to the current path of TextBox_ImageFolder, if needed
folderDialog.SelectedPath = TextBox_ImageFolder.Text
' Show the folder dialog and check if the user selected a folder
If folderDialog.ShowDialog() = DialogResult.OK Then
' Set the selected folder path in TextBox_ImageFolder
TextBox_ImageFolder.Text = folderDialog.SelectedPath
' Optionally, you can save the selected folder location to My.Settings if you want to persist it
My.Settings.Setting_ImageFolder = folderDialog.SelectedPath
My.Settings.Save()
End If
End Using
End Sub
Private Sub PictureBox_Info_From_Click(sender As Object, e As EventArgs) Handles PictureBox_Info_From.Click
' Show the message box with multiline text
MessageBox.Show("The FROM section should contain the content that you want just the elements from." & vbCrLf &
"For example: 1 note per monster, spell, item, etc." & vbCrLf &
"The ADVENTURE section should contain the Adventure content that you want markdown copies of the adventures from." & vbCrLf &
"The BOOKS section should contain the Rule Book content that you want markdown copies of." & vbCrLf &
"Anything you put in BOOKS or ADVENTURE does not need to go in FROM." & vbCrLf &
"ADVENTURES do not need to be put in books. Think of books are rule books and adventures as adventure modules." & vbCrLf & vbCrLf &
"Enter the sources as SourceAcronym," & vbCrLf &
"The last source does not need a ," & vbCrLf &
"Example:" & vbCrLf & vbCrLf &
"MM," & vbCrLf &
"PHB," & vbCrLf &
"DMG", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub Button_ObsTTRPGTutorials_Click(sender As Object, e As EventArgs) Handles Button_ObsTTRPGTutorials.Click
Dim downloadUrl = "https://obsidianttrpgtutorials.com"
Try
' Using ProcessStartInfo to open the URL
Dim processInfo As New ProcessStartInfo(downloadUrl) With {
.UseShellExecute = True
}
Process.Start(processInfo)
Catch ex As Exception
MessageBox.Show("An error occurred while trying to open the link: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim downloadUrl = "https://github.com/ebullient/ttrpg-convert-cli"
Try
' Using ProcessStartInfo to open the URL
Dim processInfo As New ProcessStartInfo(downloadUrl) With {
.UseShellExecute = True
}
Process.Start(processInfo)
Catch ex As Exception
MessageBox.Show("An error occurred while trying to open the link: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub TextBox1_TextChanged_1(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
Dim downloadUrl = "https://buymeacoffee.com/ebullient"
Try
' Using ProcessStartInfo to open the URL
Dim processInfo As New ProcessStartInfo(downloadUrl) With {
.UseShellExecute = True
}
Process.Start(processInfo)
Catch ex As Exception
MessageBox.Show("An error occurred while trying to open the link: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class