View Sidebar

A Million Little Pieces Of My Mind

Organica Core: Preparing for First Use

By: Paul S. Cilwa Viewed: 5/7/2024
Posted: 8/3/2018
Page Views: 694
Topics: #Computers #Programming #Organica #VB.NET
How to determine if Organica has ever before been run on this computer.

What happens the very first time a user puts his foot in the water, so to speak, and runs Organica? We've already made an effort to "position" the running program so that it is "in" the user's home directory. But Organica needs to be able to create a directory for itself, with at least an INI file with default preferences.

Previously we put code in Frame to locate the user directory. But that's not enough for real life. We're going to append two procedures to the ThisUser class.

The first does the work of creating an Organica.ini file in any specified location.

ThisUser.vb (append)

Private Function CreateOrganicaHome(ByVal HomePath As String) As ProfileDocument IO.Directory.CreateDirectory(HomePath) HomePath = My.Computer.FileSystem.CombinePath(HomePath, "Organica.ini") Dim IniFile As New ProfileDocument(HomePath) With IniFile .WriteData("IconPath", "[UserPhoto]") .WriteData("DisplayName", "[UserDisplayName]") .UserSince = Now.Date.ToString("d") .WriteLink("Music", KnownFolders.MyMusic().FullName, "Icons\Music.png") .WriteLink("Pictures", KnownFolders.MyPictures().FullName, "Icons\Photos.png") .WriteLink("Videos", KnownFolders.MyVideos().FullName, "Icons\Videos.png") .WriteLink("Documents", KnownFolders.MyVideos().FullName, "Icons\Documents.png") End With Return IniFile End Function

Please note that this code is going to create three links to Music, Pictures, Videos and Documents. These links include icons for those Folders. Here are the ones I chose to use, for your convenience.

Then we're ready to enhance the Directory property of ThisUser. This property has the task of determining where the initialization should take place, where the .INI file should go, and then invoke the above routine to do the work.

ThisUser.vb (enhance)

Public ReadOnly Property Directory() As String Get Dim UserPath As String Dim OrganicaPath As String UserPath = KnownFolders.MyProfile.FullName OrganicaPath = My.Computer.FileSystem.CombinePath(UserPath, "Organica") If System.IO.Directory.Exists(OrganicaPath) Then Return OrganicaPath Else If MsgBox("Welcome! Organica needs to create an initial Home folder to proceed. May I do that?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Welcome to Organica!") = MsgBoxResult.Yes Then CreateOrganicaHome(OrganicaPath) Else MsgBox("It is most gratifying that your enthusiasm for Organica continues unabated." & "We look forward to your custom in future lives.", MsgBoxStyle.Exclamation) End End If Return OrganicaPath End If End Get End Property