Esempio n. 1
0
        /**
         * Constructor method, creates directories for program, in case they dont exist
         * */
        public FormMain()
        {
            /* Creating main folder for application*/
            Global.defaultPath   = (Path.GetDirectoryName(Application.ExecutablePath)); //saving on variable current executing path
            Global.testFilesPath = Global.defaultPath + Global.testFilesPath;
            if (!Directory.Exists(Global.testFilesPath))
            {
                Directory.CreateDirectory(Global.testFilesPath);
            }
            else
            {
                /*do nothing*/
            }
            Global.stroopTestFilesPath = Global.testFilesPath + Global.stroopTestFilesPath;
            // updating local directory of new version of platform, excluding old stroop one
            if (File.Exists(Global.defaultPath + "/StroopTest.exe"))
            {
                DirectoryInfo directoryOldLst = new DirectoryInfo(Global.defaultPath + "/StroopTestFiles/lst");
                directoryOldLst.MoveTo(Global.testFilesPath + Global.listFolderName);

                DirectoryInfo directoryOldStroop = new DirectoryInfo(Global.defaultPath + "/StroopTestFiles/");
                directoryOldStroop.MoveTo(Global.stroopTestFilesPath);

                DirectoryInfo directoryOldData = new DirectoryInfo(Global.defaultPath + "/data");
                directoryOldData.MoveTo(Global.stroopTestFilesPath + Global.resultsFolderName);


                try
                {
                    File.Delete(Global.defaultPath + "/StroopTest.exe");
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }
            }
            else
            {
                /*do nothing*/
            }

            /* creating directories related to StroopTest in case they don't already exists*/
            if (!Directory.Exists(Global.stroopTestFilesPath))
            {
                Directory.CreateDirectory(Global.stroopTestFilesPath);
            }
            if (!Directory.Exists(Global.stroopTestFilesPath + Global.programFolderName))
            {
                Directory.CreateDirectory(Global.stroopTestFilesPath + Global.programFolderName);
            }
            if (!Directory.Exists(Global.stroopTestFilesPath + Global.resultsFolderName))
            {
                Directory.CreateDirectory(Global.stroopTestFilesPath + Global.resultsFolderName);
            }

            /* creating directories related to ReactionTest in case they don't already exists*/
            Global.reactionTestFilesPath = Global.testFilesPath + Global.reactionTestFilesPath;
            if (!Directory.Exists(Global.reactionTestFilesPath))
            {
                Directory.CreateDirectory(Global.reactionTestFilesPath);
            }
            if (!Directory.Exists(Global.reactionTestFilesPath + Global.programFolderName))
            {
                Directory.CreateDirectory(Global.reactionTestFilesPath + Global.programFolderName);
            }
            if (!Directory.Exists(Global.reactionTestFilesPath + Global.resultsFolderName))
            {
                Directory.CreateDirectory(Global.reactionTestFilesPath + Global.resultsFolderName);
            }

            /* creating directories related to Experiment in case they don't already exists*/
            Global.experimentTestFilesPath = Global.testFilesPath + Global.experimentTestFilesPath;
            if (!Directory.Exists(Global.experimentTestFilesPath))
            {
                Directory.CreateDirectory(Global.experimentTestFilesPath);
            }
            if (!Directory.Exists(Global.experimentTestFilesPath + Global.programFolderName))
            {
                Directory.CreateDirectory(Global.experimentTestFilesPath + Global.programFolderName);
            }
            if (!Directory.Exists(Global.experimentTestFilesPath + Global.resultsFolderName))
            {
                Directory.CreateDirectory(Global.experimentTestFilesPath + Global.resultsFolderName);
            }

            /*creating directiores related to matchingtest in case they don't already exists*/
            Global.matchingTestFilesPath = Global.testFilesPath + Global.matchingTestFilesPath;
            if (!Directory.Exists(Global.matchingTestFilesPath))
            {
                Directory.CreateDirectory(Global.matchingTestFilesPath);
            }
            if (!Directory.Exists(Global.matchingTestFilesPath + Global.programFolderName))
            {
                Directory.CreateDirectory(Global.matchingTestFilesPath + Global.programFolderName);
            }
            if (!Directory.Exists(Global.matchingTestFilesPath + Global.resultsFolderName))
            {
                Directory.CreateDirectory(Global.matchingTestFilesPath + Global.resultsFolderName);
            }

            /* creating participant folder*/
            if (!Directory.Exists(Global.testFilesPath + Global.partcipantDataPath))
            {
                Directory.CreateDirectory(Global.testFilesPath + Global.partcipantDataPath);
            }

            /* creating Lists folder*/
            if (!Directory.Exists(Global.testFilesPath + Global.listFolderName))
            {
                Directory.CreateDirectory(Global.testFilesPath + Global.listFolderName);
            }

            /*creating backup folders*/
            if (!Directory.Exists(Global.defaultPath + Global.backupFolderName))
            {
                Directory.CreateDirectory(Global.defaultPath + Global.backupFolderName);
            }
            Global.stroopTestFilesBackupPath     = Global.defaultPath + Global.backupFolderName + Global.stroopTestFilesBackupPath;
            Global.reactionTestFilesBackupPath   = Global.defaultPath + Global.backupFolderName + Global.reactionTestFilesBackupPath;
            Global.experimentTestFilesBackupPath = Global.defaultPath + Global.backupFolderName + Global.experimentTestFilesBackupPath;
            Global.matchingTestFilesBackupPath   = Global.defaultPath + Global.backupFolderName + Global.matchingTestFilesBackupPath;
            Global.listFilesBackup = Global.defaultPath + Global.backupFolderName + Global.listFilesBackup;
            if (!Directory.Exists(Global.experimentTestFilesBackupPath))
            {
                Directory.CreateDirectory(Global.experimentTestFilesBackupPath);
            }
            if (!Directory.Exists(Global.stroopTestFilesBackupPath))
            {
                Directory.CreateDirectory(Global.stroopTestFilesBackupPath);
            }
            if (!Directory.Exists(Global.reactionTestFilesBackupPath))
            {
                Directory.CreateDirectory(Global.reactionTestFilesBackupPath);
            }
            if (!Directory.Exists(Global.matchingTestFilesBackupPath))
            {
                Directory.CreateDirectory(Global.matchingTestFilesBackupPath);
            }
            if (!Directory.Exists(Global.listFilesBackup))
            {
                Directory.CreateDirectory(Global.listFilesBackup);
            }

            if (!File.Exists(Global.testFilesPath + INSTRUCTIONSFILENAME))
            {
                File.Create(Global.testFilesPath + "editableInstructions.txt").Dispose();
            }
            if (!File.Exists(Global.testFilesPath + PGRCONFIGHELPFILENAME))
            {
                File.Create(Global.testFilesPath + PGRCONFIGHELPFILENAME).Dispose();
            }

            if (Directory.Exists(Global.defaultPath + "/StroopTestFiles"))
            {
                Directory.Delete(Global.defaultPath + "/StroopTestFiles", true);
            }

            // converting old implementations of file lists to new version
            StrList.convertFileLists();

            // create default stroop and reaction programs, adding default word and color lists
            initializeDefaultPrograms();

            InitializeComponent();
            serialPort1.Open();

            initializeParticipants();

            _contentPanel  = contentPanel;
            dirPathSL.Text = Global.testFilesPath;
        }