Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
amymor authored Mar 9, 2024
1 parent e3d1bfa commit 1374791
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 80 deletions.
10 changes: 5 additions & 5 deletions 1.Slideshow.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ ListFiles.exe "%FolderPath%">> list.ini
SET /P "LineNumber= Enter the line number to use as a variable. If you want to set first image as background, then enter 1:"

:: create ini to store number of currnet background
IF NOT EXIST "CurrentBG*.ini" (
type NUL > CurrentBG.ini
IF NOT EXIST "CurrentBG*" (
type NUL > CurrentBG1
)
:: rename previous CurrentBG*.ini to specified number:
REN "CurrentBG*.ini" "CurrentBG%LineNumber%.ini"
:: rename previous CurrentBG* to specified number:
REN "CurrentBG*" "CurrentBG%LineNumber%"
:: find the .ini file and set it as a variable:
FOR /R "%~dp0" %%F IN (CurrentBG*.ini) DO SET "IniFile=%%~nF"
FOR /R "%~dp0" %%F IN (CurrentBG*) DO SET "IniFile=%%~nF"
:: remove the CurrentBG
SET "LineNumber=%IniFile:CurrentBG=%"

Expand Down
196 changes: 121 additions & 75 deletions JBSGUI.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ Public Class SlideshowForm
Private ButtonPrevious As New Button()
Private ButtonNext As New Button()
Private ButtonBGName As New Button()
Public Sub New()
InitializeComponent()
LoadInitialData()
End Sub
Private userInitiatedChange As Boolean = False

Private Sub InitializeComponent()
Public Sub New()
Me.Size = New Size(560, 120)
' Me.AllowDrop = True
Me.Text = "JBS GUI - amymor OgomnamO"
Expand All @@ -38,10 +35,13 @@ Public Class SlideshowForm
NumericUpDownCurrentBG.Size = New Size(120, 20)
NumericUpDownCurrentBG.Font = New Font("Segoe UI", 14) ' Set font size
NumericUpDownCurrentBG.Value = 1
NumericUpDownCurrentBG.Maximum = 10000000 ' Remove the limit
NumericUpDownCurrentBG.Minimum = 1 ' Minimum value

ButtonBrowse.Location = New Point(390, 10)
ButtonBrowse.Size = New Size(75, 30)
ButtonBrowse.Text = "Browse"
ButtonBrowse.Font = New Font("Segoe UI", 11) ' Set font size

ButtonCreateList.Location = New Point(465, 10) ' Position the new button
ButtonCreateList.Size = New Size(85, 30)
Expand All @@ -63,6 +63,7 @@ Public Class SlideshowForm
ButtonBGName.Location = New Point(270, 50)
ButtonBGName.Size = New Size(280, 32)
ButtonBGName.TextAlign = ContentAlignment.MiddleLeft
ButtonBGName.Font = New Font("Segoe UI", 10) ' Set font size

' Dark theme =======================================================
Me.BackColor = Color.FromArgb(40, 35, 40)
Expand Down Expand Up @@ -115,12 +116,36 @@ Public Class SlideshowForm
ButtonBGName.FlatAppearance.BorderColor = Color.FromArgb(84, 70, 177)
ButtonBGName.FlatAppearance.BorderSize = 1

' = startup TextBoxFolderPath as FolderPath.ini=====================================================
If File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FolderPath.ini")) Then
TextBoxFolderPath.Text = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FolderPath.ini")).Trim()
End If
' = startup Numeric as CurrentBG*.ini and ButtonBGName as image Name ============================
' Load current background number from CurrentBG*.ini
Dim currentBGFile = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory).FirstOrDefault(Function(f) Path.GetFileName(f).StartsWith("CurrentBG"))
If currentBGFile IsNot Nothing Then
Dim currentBGNumber = Integer.Parse(Path.GetFileNameWithoutExtension(currentBGFile).Substring("CurrentBG".Length))
NumericUpDownCurrentBG.Value = currentBGNumber

' Initialize ButtonBGName.Text with the name of the current background image
Dim imageName = GetImageNameFromList(currentBGNumber)
If Not String.IsNullOrEmpty(imageName) Then
ButtonBGName.Text = Path.GetFileName(imageName) ' Update the button's text
Else
ButtonBGName.Text = "List.ini is empty or does not exist." ' Update the button's text
End If
Else
Dim imageName = GetImageNameFromList("1")
ButtonBGName.Text = Path.GetFileName(imageName) ' Update the button's text
' ButtonBGName.Text = "1. Browse > 2. Create List"
End If
' AddHandler=====================================================
AddHandler TextBoxFolderPath.TextChanged, AddressOf TextBoxFolderPath_TextChanged ' Handle text
AddHandler ButtonBrowse.Click, AddressOf ButtonBrowse_Click
AddHandler ButtonCreateList.Click, AddressOf ButtonCreateList_Click
AddHandler ButtonPrevious.Click, AddressOf ButtonPrevious_Click
AddHandler ButtonNext.Click, AddressOf ButtonNext_Click
AddHandler NumericUpDownCurrentBG.ValueChanged, AddressOf NumericUpDownCurrentBG_ValueChanged
AddHandler ButtonBGName.Click, AddressOf ButtonBGName_Click

' AddHandler Me.DragEnter, AddressOf Form_DragEnter
Expand All @@ -133,7 +158,10 @@ Public Class SlideshowForm
Me.Controls.Add(ButtonPrevious)
Me.Controls.Add(ButtonNext)
Me.Controls.Add(ButtonBGName)

ButtonBrowse.Select() ' focus to the ButtonBrowse at startup
End Sub

' DragDrop=====================================================
' Private Sub Form_DragEnter(sender As Object, e As DragEventArgs) ' Check if the dragged item is a folder
' If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Expand All @@ -151,28 +179,12 @@ Public Class SlideshowForm
' File.WriteAllText("FolderPath.ini", files(0).Trim())
' End If
' End Sub
' live Text-box and Numeric-field=====================================================

Private Sub LoadInitialData()
' Load initial folder path from FolderPath.ini
If File.Exists("FolderPath.ini") Then
TextBoxFolderPath.Text = File.ReadAllText("FolderPath.ini").Trim()
End If
' Load current background number from CurrentBG*.ini
Dim currentBGFile = Directory.GetFiles(".").FirstOrDefault(Function(f) Path.GetFileName(f).StartsWith("CurrentBG"))
If currentBGFile IsNot Nothing Then
Dim currentBGNumber = Integer.Parse(Path.GetFileNameWithoutExtension(currentBGFile).Substring("CurrentBG".Length))
NumericUpDownCurrentBG.Maximum = Decimal.MaxValue ' Remove the limit or set a specific limit
NumericUpDownCurrentBG.Value = currentBGNumber
NumericUpDownCurrentBG.Minimum = 1 ' Minimum value
ButtonBrowse.Select() ' focus to the ButtonBrowse at startup
End If
End Sub
' live Text-box =====================================================

Private Sub TextBoxFolderPath_TextChanged(sender As Object, e As EventArgs)
' Update FolderPath.ini with the new text box value
File.WriteAllText("FolderPath.ini", TextBoxFolderPath.Text.Trim())
End Sub
Private Sub TextBoxFolderPath_TextChanged(sender As Object, e As EventArgs)
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FolderPath.ini"), TextBoxFolderPath.Text.Trim())
End Sub
' Browse=====================================================
Private Sub ButtonBrowse_Click(sender As Object, e As EventArgs)
' Initialize the OpenFileDialog
Expand All @@ -191,7 +203,8 @@ Private Sub ButtonBrowse_Click(sender As Object, e As EventArgs)
' Get the selected folder path
Dim selectedFolderPath As String = Path.GetDirectoryName(openFileDialog.FileName)
TextBoxFolderPath.Text = selectedFolderPath
File.WriteAllText("FolderPath.ini", selectedFolderPath)
' File.WriteAllText("FolderPath.ini", selectedFolderPath)
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FolderPath.ini"), selectedFolderPath)
End If
End Using
End Sub
Expand All @@ -202,7 +215,7 @@ Private Sub ButtonCreateList_Click(sender As Object, e As EventArgs)
If Not String.IsNullOrEmpty(folderPath) Then
' Ensure the folder path is properly quoted
Dim quotedFolderPath As String = String.Format("""{0}""", folderPath)
Dim startInfo As New ProcessStartInfo("ListFiles.exe", quotedFolderPath)
Dim startInfo As New ProcessStartInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ListFiles.exe"), quotedFolderPath)
startInfo.RedirectStandardOutput = True
startInfo.UseShellExecute = False
startInfo.CreateNoWindow = True
Expand All @@ -211,68 +224,87 @@ Private Sub ButtonCreateList_Click(sender As Object, e As EventArgs)
process.Start()
Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()
File.WriteAllText("List.ini", output)

' Check if the output is not empty
If Not String.IsNullOrWhiteSpace(output) Then
' Write the output to List.ini
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini"), output)


' Rename the existing CurrentBG file to the new number
Dim currentBGFile = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory).FirstOrDefault(Function(f) Path.GetFileName(f).StartsWith("CurrentBG"))
If currentBGFile IsNot Nothing Then
File.Move(currentBGFile, "CurrentBG1")
Else
' If there's no existing CurrentBG file, create a new CurrentBG1
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CurrentBG1"), "")
End If

UpdateBackgroundNumber()
Else
' If the output is empty, update the button's text to indicate no images were found
ButtonBGName.Text = "The folder did not contain any images."
End If
End Using
End If
End Sub


' UpdateBackgroundNumber=====================================================
Private Sub ButtonPrevious_Click(sender As Object, e As EventArgs)
userInitiatedChange = True
' Check if the List.ini file exists
If File.Exists("List.ini") Then
If File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")) Then
' Determine the total number of lines in List.ini
Dim totalLines As Integer = File.ReadAllLines("List.ini").Length
Dim totalLines As Integer = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")).Length
If totalLines > 0 Then
' Check if the current value is at the minimum
If NumericUpDownCurrentBG.Value = 1 Then
' Set to the last line
NumericUpDownCurrentBG.Value = totalLines
Else
If NumericUpDownCurrentBG.Value > 1 Then
' Decrement the current background number
NumericUpDownCurrentBG.Value -= 1
Else
' Set to the last line
NumericUpDownCurrentBG.Value = totalLines
End If
UpdateBackgroundNumber()
End If
Else
' Optionally, handle the case where the List.ini file does not exist
' MessageBox.Show("List.ini does not exist.")
If NumericUpDownCurrentBG.Value > 1 Then
NumericUpDownCurrentBG.Value -= 1
End If
ButtonBGName.Text = "List.ini does not exist." ' Update the button's text
' Handle the case where the List.ini file does not exist
ButtonBGName.Text = "List.ini is empty or does not exist." ' Update the button's text
End If
End Sub

' ---------------------------------------------------------------------------------------------------------------------------
Private Sub ButtonNext_Click(sender As Object, e As EventArgs)
userInitiatedChange = True
' Check if the List.ini file exists
If File.Exists("List.ini") Then
If File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")) Then
' Determine the total number of lines in List.ini
Dim totalLines As Integer = File.ReadAllLines("List.ini").Length
Dim totalLines As Integer = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")).Length
If totalLines > 0 Then
' Check if the current value is at the maximum
If NumericUpDownCurrentBG.Value = totalLines Then
' Reset to the first line
NumericUpDownCurrentBG.Value = 1
Else
If NumericUpDownCurrentBG.Value < totalLines Then
' Increment the current background number
NumericUpDownCurrentBG.Value += 1
Else
' Reset to the first line
NumericUpDownCurrentBG.Value = 1
End If
UpdateBackgroundNumber()
End If
Else
' Optionally, handle the case where the List.ini file does not exist
' MessageBox.Show("List.ini does not exist.")
NumericUpDownCurrentBG.Value += 1
ButtonBGName.Text = "List.ini does not exist." ' Update the button's text
' Handle the case where the List.ini file does not exist
ButtonBGName.Text = "List.ini is empty or does not exist." ' Update the button's text
End If
End Sub

' ---------------------------------------------------------------------------------------------------------------------------
Private Sub NumericUpDownCurrentBG_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDownCurrentBG.ValueChanged
Private Sub NumericUpDownCurrentBG_ValueChanged(sender As Object, e As EventArgs)
If userInitiatedChange Then
' Check if the List.ini file exists
If File.Exists("List.ini") Then
If File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")) Then
' Determine the total number of lines in List.ini
Dim totalLines As Integer = File.ReadAllLines("List.ini").Length
Dim totalLines As Integer = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")).Length
If totalLines > 0 Then
' Update the Maximum property to match the total number of lines
NumericUpDownCurrentBG.Maximum = totalLines
Expand All @@ -287,40 +319,57 @@ Private Sub NumericUpDownCurrentBG_ValueChanged(sender As Object, e As EventArgs
End If
End If
Else
' Optionally, handle the case where the List.ini file does not exist
' MessageBox.Show("List.ini does not exist.")
ButtonBGName.Text = "List.ini does not exist." ' Update the button's text
' Handle the case where the List.ini file does not exist
ButtonBGName.Text = "List.ini is empty or does not exist." ' Update the button's text
End If
' Update the background number

' Update the background number immediately
UpdateBackgroundNumber()
End If
' set the flag to True to make the NumericUpDown live
userInitiatedChange = True
End Sub

' ---------------------------------------------------------------------------------------------------------------------------
Private Sub UpdateBackgroundNumber()
' Update the current background number in CurrentBG*.ini
Dim currentBGNumber = NumericUpDownCurrentBG.Value
Dim currentBGFile = Directory.GetFiles(".").FirstOrDefault(Function(f) Path.GetFileName(f).StartsWith("CurrentBG"))
If currentBGFile IsNot Nothing Then
File.Delete(currentBGFile)
End If
File.WriteAllText("CurrentBG" & currentBGNumber & ".ini", "")
Private Sub UpdateBackgroundNumber()
Dim totalLines As Integer = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")).Length
If totalLines > 0 Then
' Update the Maximum property to match the total number of lines
NumericUpDownCurrentBG.Maximum = totalLines
End If
' Update the current background number in CurrentBG*
Dim currentBGNumber = NumericUpDownCurrentBG.Value
Dim currentBGFile = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory).FirstOrDefault(Function(f) Path.GetFileName(f).StartsWith("CurrentBG"))

If currentBGFile IsNot Nothing Then
' Construct the new file name based on the current background number
Dim newBGFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CurrentBG" & currentBGNumber)

' Rename the existing CurrentBG file to the new number
File.Move(currentBGFile, newBGFileName)
Else
' If there's no existing CurrentBG file, create a new one with the current background number
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CurrentBG" & currentBGNumber), "")
End If


' Set Background=====================================================
' Set the desktop background using JBS.exe
Dim imageName = GetImageNameFromList(currentBGNumber)
If Not String.IsNullOrEmpty(imageName) Then
ButtonBGName.Text = Path.GetFileName(imageName) ' Update the button's text
' Construct the full path to the image, ensuring it's properly quoted
Dim fullPath As String = String.Format("""{0}\{1}""", TextBoxFolderPath.Text, imageName)
Process.Start("JBS.exe", fullPath)
Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "JBS.exe"), fullPath)
' Else
' ButtonBGName.Text = "No Image Selected" ' Update the button's text
End If
End Sub

' ---------------------------------------------------------------------------------------------------------------------------
Private Function GetImageNameFromList(currentBGNumber As Integer) As String
Dim listFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "List.ini")
' Check if the List.ini file exists
If File.Exists("List.ini") Then
Dim lines = File.ReadAllLines("List.ini")
If File.Exists(listFilePath) Then
Dim lines = File.ReadAllLines(listFilePath)
If lines.Length >= currentBGNumber Then
Return lines(currentBGNumber - 1)
End If
Expand All @@ -345,13 +394,10 @@ End Sub

' =====================================================
' Other existing event handlers...
End Class


Public Module Program
Public Sub Main()
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New SlideshowForm())
End Sub
End Module
End Class

0 comments on commit 1374791

Please sign in to comment.