FilePicker - ORF-4450/PitScouting GitHub Wiki

Variables

DS

DataStorage

DataStorage script to pull data from.

MainMenu

GameObject

The parent GameObject of all the other GameObjects that the main menu consists of, for easier access of enabling and disabling the main menu.

ScoutingMenu

GameObject

The parent GameObject of all the other GameObjects that the scouting menu consists of, for easier access of enabling and disabling the scouting menu.

FileMenu

GameObject

The parent GameObject of all the other GameObjects that the file menu consists of, for easier access of enabling and disabling the file menu.

dropdown

Dropdown

A dropdown of all the possible files to choose from

dataViewer

Text

If the file is a text file, shows the text. Does not get disabled if this is false, but has no content and the DisplayedImage is shown instead.

file

FileInfo

Stores the file that is currently being worked with

resultText

Text

Tells the user the result of the current action.

Displayed Image

RawImage

If the file is an image, shows the image. Otherwise does nothing and his disabled.

Functions

loadMenu()

loadMenu()

Enables the Main, Scouting, and File menu game object's in hierarchy with SetActive

Start()

Start()

Sets DS to an instance of DataStorage (not entirely sure what instance as it doesn't use GameObject.GetComponent<>();

LateUpdate()

LateUpdate

If dropdown doesnt exist, only has 1 option, or the last option is ".DS_Store" it returns

Sets tmp_file to a new FileInfo object for the path (Application.persistentDataPath + Path.DirectorySeparatorChar + dropdown.captionText.text)

If file is null and tmp_file exists, the contents file are set to the contents of tmp_file. The dataViewer text then gets set to the text in file.

If file is not null and does not exist, sets the first value of the dropdown to 0, refreshes whats shown, and then returns

If tmp_file is equal to file, it returns

File gets set to tmp_file

If file is a txt, dataViewer text gets set to the contents of file

If file is a png, the image display (DisplayedImage) gets enabled. It then checks if tmpFileName is not equal to getStringFromFile(tmp_file). If that returns as true then they create a new Texture2D called tex. Tex is loaded as getStringFromFile(tmp_file) using LoadImage (File.ReadAllBytes(getStringFromFile(tmp_file)). After tex is loaded it then sets DisplayedImage to tex and then sets tmpFileName to the contents of tmp_file. Otherwise the file is not a png, and DisplayedImage is disabled

Update()

Update()

If dropdown is null it returns

It creates a new List of the options in a Dropdown called files

It creates a DirectoryInfo of Application.persistentDataPath.

It adds a new option called "Choose a file" to files

For every single file in directory.GetFiles() if the file name starts with "." or the extension is a ".json" it will add a new option called with the name of the file to files

Finally if the options of dropdown is the equal to files, then all the options in dropdown get set to all the files.

string getStringFromFile()

getStringFromFile(FileInfo)

If the argument file does not exist, it returns with the result "File not found"

Creates a StreamReader called sr that is equal to the text that was red from the argument file

Creates a new string called data that is equal to the return value from using getStringFromFile on the argument file

It then closes sr and returns the local data string

loadFromSelectedFile()

loadFromSelectedFile

If file is null it returns

It creates a new string called raw which is equal to the string obtained from file using getStringFromFile

It creates a new bool called valid which is defaulted to false

For every single string, called line, in a new string[] creating by splitting raw with Split() If after splitting line again based off of ";" the result for the first string out of all the substrings of line for any line is Version, valid becomes true.

If valid is not true, it sets the text of resultText to and gives warnings about the file being invalid and the version tag missing, and then returns

The do a foreach a second time with the same arguments as the previous time, and if line is null it continues and skips to the next line substring of raw. They create a new string[] called broken with all the strings inside the array being created by splitting line by ";". If the first string of broken is version, but the second string is not equal to the version inside of the dictionary DS.data it sets the test of resultText about the versions being different, and returns. If the dictionary DS.inputs does not contain the first string in broken it continues and skips to the next line substring of raw. It changes the value of the the key that is equal to the first string in broken in the inputs dictionary of DS to the second string in broken. ResultText changes to say it has been updated.

clearFiles()

clearFiles()

It creates a new DirectoryInfo at Application.persistentDataPath called directory

For every file in the directory if its a txt or png file it gets deleted with resultText giving information about whether its about to be deleted or done being deleted

resultText gives info to the user by saying that all unuploaded files are now deleted, and now its going to delete all uploaded files

It creates a new DirectoryInfo at Application.persistentDataPath/uploaded called uploaded

If uploaded does exist, for every single folder it checks if there is any files, and if there are it deletes all of them, and then deletes the folder and is constantly change resultText so the user would know. After all the folders are deleted uploaded also gets deleted

It tells the user that all deletion is done by changing resultText and then sets tmpFileName to null.