Esempio n. 1
0
        /// <summary>
        /// Returns all default challenges from specified reference folder
        /// </summary>
        /// <param name="referenceFolder"></param>
        public static Collection <DFE> LoadDefaultChallenges(string referenceFolder)
        {
            Collection <DFE> returnedChallenges = new Collection <DFE>();

            // Get all files in specified DFE folder
            DirectoryInfo dirInfo = new DirectoryInfo(referenceFolder);

            if (!dirInfo.Exists)
            {
                Directory.CreateDirectory(referenceFolder);
            }

            string[] returnedTracks = Directory.GetFiles(referenceFolder, LibraryConstants.FILTER_DFE);

            foreach (string anotherFile in returnedTracks)
            {
                DFE dfeFile = TduFile.GetFile(anotherFile) as DFE;

                if (dfeFile == null)
                {
                    Log.Warning("DFE file failed to load: " + anotherFile);
                }
                else
                {
                    returnedChallenges.Add(dfeFile);
                }
            }

            // Log message
            Log.Info("Original challenges found and loaded: " + returnedChallenges.Count);

            return(returnedChallenges);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts specified IGE challenges to DFE files
        /// </summary>
        /// <param name="igeFiles"></param>
        private static Couple <int> _ConvertIGEtoDFE(IGE[] igeFiles)
        {
            Couple <int> returnedCount = new Couple <int>(0, 0);

            if (igeFiles != null)
            {
                int totalCount   = igeFiles.Length;
                int successCount = 0;

                foreach (IGE anotherIGE in igeFiles)
                {
                    try
                    {
                        DFE convertedTrack = anotherIGE;

                        // New file name
                        string tracksFolder = AppConstants.FOLDER_TRACKS;
                        //string newFileName = new FileInfo(convertedTrack.FileName).Name;
                        string targetFileName = string.Concat(tracksFolder, @"\", DFE.FILE_DATA_DFE, File2.GetValidFileName(convertedTrack.TrackName, false)
                                                              /*File2.GetNameFromFilename(newFileName)*/);

                        convertedTrack.SaveAs(targetFileName);
                        successCount++;
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Unable to convert IGE track to DFE.", ex);
                    }
                }

                returnedCount = new Couple <int>(successCount, totalCount);
            }

            return(returnedCount);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns default challenge replaced by specified custom track
        /// </summary>
        /// <param name="customFileName"></param>
        /// <returns>Null if no challenge has been found</returns>
        private DFE _GetReplacedChallenge(string customFileName)
        {
            DFE returnedChallenge = null;

            if (!string.IsNullOrEmpty(customFileName))
            {
                // Extracts replacing information
                string[] splitted = customFileName.Split(new[] { _REPLACING_SEPARATOR }, 2, StringSplitOptions.RemoveEmptyEntries);

                if (splitted.Length == 2)
                {
                    int  challengeIndex;
                    bool parsingResult = int.TryParse(splitted[1], out challengeIndex);

                    if (parsingResult && _DefaultChallenges.Count > challengeIndex)
                    {
                        returnedChallenge = _DefaultChallenges[challengeIndex];
                    }
                    else
                    {
                        Log.Warning("Invalid replacing information in file name: " + customFileName);
                    }
                }
            }

            return(returnedChallenge);
        }
Esempio n. 4
0
        private void deleteTrackToolStripButton_Click(object sender, EventArgs e)
        {
            // Click on 'delete button'
            if (customTracksListView.SelectedItems.Count == 1 &&
                MessageBoxes.ShowQuestion(this, _QUESTION_DELETE_TRACK, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Cursor = Cursors.WaitCursor;

                try
                {
                    ListViewItem selectedItem  = customTracksListView.SelectedItems[0];
                    DFE          selectedTrack = selectedItem.Tag as DFE;

                    if (selectedTrack != null)
                    {
                        File.Delete(selectedTrack.FileName);

                        // Refresh
                        _RefreshCustomList();

                        StatusBarLogManager.ShowEvent(this, _STATUS_DELETE_OK);
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxes.ShowError(this, ex);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }
Esempio n. 5
0
        private void trackTimer_Tick(object sender, EventArgs e)
        {
            // Timer interval reached
            // For each selected custom track, locate replaced name in DFE folder
            foreach (ListViewItem anotherItem in customTracksListView.Items)
            {
                try
                {
                    DFE currentTrack = anotherItem.Tag as DFE;

                    if (currentTrack != null)
                    {
                        FileInfo customTrackInfo   = new FileInfo(currentTrack.FileName);
                        DFE      replacedChallenge = _GetReplacedChallenge(customTrackInfo.Name);

                        if (replacedChallenge != null)
                        {
                            FileInfo replacedChallengeInfo = new FileInfo(replacedChallenge.FileName);
                            string   tduDfeFileName        = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Data_DFE), replacedChallengeInfo.Name);
                            FileInfo dfeTrackInfo          = new FileInfo(tduDfeFileName);

                            if (anotherItem.Checked)
                            {
                                // Checked > synchronization
                                if (dfeTrackInfo.Exists && dfeTrackInfo.LastWriteTime != customTrackInfo.LastWriteTime)
                                {
                                    File.Copy(currentTrack.FileName, tduDfeFileName, true);

                                    string message = string.Format(_FORMAT_TRACK_SYNC_OK, currentTrack.TrackName, replacedChallenge.TrackName);

                                    StatusBarLogManager.ShowEvent(this, message);
                                    SystemSounds.Exclamation.Play();
                                }
                            }

                            /*else
                             * {
                             *  // Unchecked > restoration
                             *  // Disabled beacause of conflicts
                             *  if (dfeTrackInfo.Exists && dfeTrackInfo.LastWriteTime != replacedChallengeInfo.LastWriteTime)
                             *  {
                             *      File.Copy(replacedChallenge.FileName, tduDfeFileName, true);
                             *
                             *      string message = string.Format(_FORMAT_TRACK_RESTORE_OK, replacedChallenge.TrackName);
                             *
                             *      StatusBarLogManager.ShowEvent(this, message);
                             *      SystemSounds.Exclamation.Play();
                             *  }
                             * }*/
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("A track synchronization issue has occured.", ex);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns replaced challenge name to be displayed
        /// </summary>
        /// <param name="replacedChallenge"></param>
        /// <returns></returns>
        private string _GetReplacedChallengeName(DFE replacedChallenge)
        {
            string returnedName = _ITEM_REPLACES_NONE;

            if (replacedChallenge != null)
            {
                returnedName = _GetNameFromResource(replacedChallenge.TrackNameDbResource);
            }

            return(returnedName);
        }
Esempio n. 7
0
        /// <summary>
        /// Changes challenge replacement label
        /// </summary>
        /// <param name="isNoReplacement">true to indicate the track won't replace any challenge</param>
        private void _UpdateReplacementLabel(bool isNoReplacement)
        {
            if (isNoReplacement)
            {
                _ReplacedChallenge = null;
            }
            else
            {
                string fileName = new FileInfo(_CurrentTrack.FileName).Name;

                if (_ReplacedChallenge == null)
                {
                    _ReplacedChallenge = _GetReplacedChallenge(fileName);
                }
            }

            replacedLinkLabel.Text = _GetReplacedChallengeName(_ReplacedChallenge);
        }
Esempio n. 8
0
        private void replacedLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            // Click on replaced track link > display genuine track list
            try
            {
                Cursor = Cursors.WaitCursor;

                OriginalTracksDialog dlg = new OriginalTracksDialog(_DefaultChallenges, _HousesResource, true);
                DialogResult         dr  = dlg.ShowDialog(this);

                if (dr == DialogResult.OK)
                {
                    int selectedTrackIndex = dlg.SelectedTrackId;

                    if (selectedTrackIndex == -1)
                    {
                        // No replacement
                        _ReplacedChallenge = null;
                    }
                    else
                    {
                        _ReplacedChallenge = _DefaultChallenges[selectedTrackIndex];
                    }

                    // Replacement label update
                    _UpdateReplacementLabel(_ReplacedChallenge == null);

                    // Flag
                    _IsChanged = true;
                }
            }
            catch (Exception ex)
            {
                MessageBoxes.ShowError(this, ex);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Export specified track items
        /// </summary>
        /// <param name="trackItems"></param>
        /// <param name="packName"></param>
        /// <param name="targetFolder"></param>
        private static void _ExportTracks(IEnumerable <ListViewItem> trackItems, string packName, string targetFolder)
        {
            if (trackItems != null && !string.IsNullOrEmpty(packName) && !string.IsNullOrEmpty(targetFolder) && Directory.Exists(targetFolder))
            {
                // Directories
                string packFolder    = string.Concat(targetFolder, @"\", File2.GetValidFileName(packName, true));
                string tracksFolder  = string.Concat(packFolder, LibraryConstants.FOLDER_TRACKS);
                string defaultFolder = string.Concat(packFolder, LibraryConstants.FOLDER_DEFAULT);

                Directory.CreateDirectory(packFolder);
                Directory.CreateDirectory(tracksFolder);

                // Libraries
                string frameworkFileName = string.Concat(Tools.WorkingPath, DjeFramework1.LibraryProperties.FILE_LIBRARY);
                string tduLibFileName    = string.Concat(Tools.WorkingPath, TDUModdingLibrary.LibraryProperties.FILE_LIBRARY);

                File.Copy(frameworkFileName, string.Concat(packFolder, DjeFramework1.LibraryProperties.FILE_LIBRARY), true);
                File.Copy(tduLibFileName, string.Concat(packFolder, TDUModdingLibrary.LibraryProperties.FILE_LIBRARY), true);

                // EXE files
                string tpFileName = string.Concat(Tools.WorkingPath, LibraryConstants.FOLDER_TRACKS, AppConstants.FILE_EXE_TRACKPACK);

                File.Copy(tpFileName, string.Concat(packFolder, AppConstants.FILE_EXE_TRACKPACK), true);

                // Exported tracks
                foreach (ListViewItem anotherItem in trackItems)
                {
                    DFE customTrack = anotherItem.Tag as DFE;

                    if (customTrack != null)
                    {
                        FileInfo fi = new FileInfo(customTrack.FileName);
                        File.Copy(customTrack.FileName, string.Concat(tracksFolder, @"\", fi.Name), true);
                    }
                }

                // Default challenges
                File2.CopyDirectory(string.Concat(Tools.WorkingPath, LibraryConstants.FOLDER_XML, LibraryConstants.FOLDER_DEFAULT, LibraryConstants.FOLDER_CHALLENGES), defaultFolder);
            }
        }
Esempio n. 10
0
        private void customTracksListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Another custom track has been selected
            if (customTracksListView.SelectedItems.Count == 1)
            {
                try
                {
                    Cursor = Cursors.WaitCursor;

                    _CurrentTrack      = customTracksListView.SelectedItems[0].Tag as DFE;
                    _ReplacedChallenge = null;

                    _RefreshTrackDetails();
                }
                catch (Exception ex)
                {
                    MessageBoxes.ShowError(this, ex);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Returns the right TDUFile according to specified file.
        /// </summary>
        /// <param name="fileName">file name, without path</param>
        /// <returns>null if file is from an unsupported type</returns>
        public static TduFile GetFile(string fileName)
        {
            TduFile  tduFile = new Regular();
            FileInfo fi      = new FileInfo(fileName);

            // New mapping management

            // Cameras
            if (Regex.IsMatch(fileName, Cameras.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new Cameras(fileName);
                }
                else
                {
                    tduFile = new Cameras();
                }
            }
            // AIConfig
            else if (Regex.IsMatch(fileName, AIConfig.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new AIConfig(fileName);
                }
                else
                {
                    tduFile = new AIConfig();
                }
            }
            // DB
            else if (Regex.IsMatch(fileName, DB.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new DB(fileName);
                }
                else
                {
                    tduFile = new DB();
                }
            }
            // BNK
            else if (Regex.IsMatch(fileName, BNK.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                tduFile = new BNK(fileName);
            }
            // DDS
            else if (Regex.IsMatch(fileName, DDS.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new DDS(fileName);
                }
                else
                {
                    tduFile = new DDS();
                }
            }
            // 2DB
            else if (Regex.IsMatch(fileName, _2DB.FILENAME_PATTERN, RegexOptions.IgnoreCase) ||
                     Regex.IsMatch(fileName, _2DB.FILENAME_OLD_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new _2DB(fileName);
                }
                else
                {
                    tduFile = new _2DB();
                }
            }
            // MAP
            else if (Regex.IsMatch(fileName, MAP.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new MAP(fileName);
                }
                else
                {
                    tduFile = new MAP();
                }
            }
            // XMB
            else if (Regex.IsMatch(fileName, XMB.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new XMB(fileName);
                }
                else
                {
                    tduFile = new XMB();
                }
            }
            // WAV + XMB_WAV
            else if (Regex.IsMatch(fileName, XMB_WAV.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                try
                {
                    if (fi.Exists)
                    {
                        tduFile = new XMB_WAV(fileName);
                    }
                    else
                    {
                        tduFile = new XMB_WAV();
                    }
                }
                catch (FormatException)
                {
                    // standard WAV file
                }
            }
            // PCH
            else if (Regex.IsMatch(fileName, PCH.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                tduFile = new PCH(fileName);
            }
            // DB Resources
            else if (Regex.IsMatch(fileName, DBResource.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                if (fi.Exists)
                {
                    tduFile = new DBResource(fileName);
                }
                else
                {
                    tduFile = new DBResource();
                }
            }
            // DFE
            else if (Regex.IsMatch(fileName, DFE.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                tduFile = new DFE(fileName);
            }
            // IGE
            else if (Regex.IsMatch(fileName, IGE.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                tduFile = new IGE(fileName);
            }
            // Regular by default
            else
            {
                tduFile = new Regular();
            }

            // To update common information
            tduFile._FinalizeLoading(fileName);

            return(tduFile);
        }
Esempio n. 12
0
        /// <summary>
        /// Updates custom tracks list view
        /// </summary>
        private void _RefreshCustomList()
        {
            // Stores checked tracks
            ListView2.StoreCheckedItems(customTracksListView);

            // Stores selected index
            ListView2.StoreSelectedIndex(customTracksListView);

            customTracksListView.Items.Clear();

            // Get all custom tracks in tracks folder
            string        tracksFolder = AppConstants.FOLDER_TRACKS;
            DirectoryInfo tracksDir    = new DirectoryInfo(tracksFolder);

            if (!tracksDir.Exists)
            {
                // Must be created
                tracksDir = Directory.CreateDirectory(tracksFolder);
            }

            FileInfo[] allTracks = tracksDir.GetFiles();

            foreach (FileInfo anotherTrackFile in allTracks)
            {
                // Loading DFE file
                DFE dfeFile;

                try
                {
                    dfeFile = TduFile.GetFile(anotherTrackFile.FullName) as DFE;

                    if (dfeFile == null)
                    {
                        throw new Exception("Unknown track file format.");
                    }


                    ListViewItem li = new ListViewItem(dfeFile.TrackName)
                    {
                        Tag = dfeFile
                    };

                    li.SubItems.Add(dfeFile.ChallengeMode.ToString());
                    li.SubItems.Add(dfeFile.ChallengeType.ToString());

                    // Gets replaced challenge from file name
                    DFE replacedChallenge = _GetReplacedChallenge(anotherTrackFile.Name);

                    if (replacedChallenge == null)
                    {
                        li.SubItems.Add(_ITEM_REPLACES_NONE);
                    }
                    else
                    {
                        li.SubItems.Add(_GetReplacedChallengeName(replacedChallenge));
                    }

                    // File name
                    li.SubItems.Add(new FileInfo(dfeFile.FileName).Name);

                    customTracksListView.Items.Add(li);
                }
                catch (Exception ex)
                {
                    Log.Error("Unable to load custom track: " + anotherTrackFile.Name, ex);
                }
            }

            // Restores selected index
            ListView2.RestoreSelectedIndex(customTracksListView);

            // Restores checked tracks
            ListView2.RestoreCheckedItems(customTracksListView);
        }
Esempio n. 13
0
        private void exportToolStripButton_Click(object sender, EventArgs e)
        {
            // Click on Export button...
            Collection <ListViewItem> checkedItems = ListView2.GetCheckedItems(customTracksListView);

            Cursor = Cursors.WaitCursor;

            try
            {
                if (checkedItems.Count == 0)
                {
                    MessageBoxes.ShowWarning(this, _WARNING_CHECK_EXPORT);
                }
                else
                {
                    // All tracks must have replacing information
                    foreach (ListViewItem anotherItem in checkedItems)
                    {
                        DFE currentTrack = anotherItem.Tag as DFE;

                        if (currentTrack != null)
                        {
                            FileInfo fi = new FileInfo(currentTrack.FileName);
                            DFE      replacedChallenge = _GetReplacedChallenge(fi.Name);

                            if (replacedChallenge == null)
                            {
                                throw new Exception(_ERROR_REPLACE_EXPORT);
                            }
                        }
                    }


                    // Asks for track name
                    PromptBox    pBox = new PromptBox(_TITLE_EXPORT, _MSG_EXPORT, _NAME_EXPORT);
                    DialogResult dr   = pBox.ShowDialog(this);

                    if (dr == DialogResult.OK)
                    {
                        // Displays export target folder
                        folderBrowserDialog.Description = _MSG_PATH_EXPORT;
                        dr = folderBrowserDialog.ShowDialog(this);

                        if (dr == DialogResult.OK)
                        {
                            _ExportTracks(checkedItems, pBox.ReturnValue, folderBrowserDialog.SelectedPath);

                            string msg = string.Format(_FORMAT_EXPORT_OK, checkedItems.Count);

                            StatusBarLogManager.ShowEvent(this, msg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxes.ShowError(this, ex);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Esempio n. 14
0
        private void checkpointsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Click on Import Checkpoints...
            if (customTracksListView.SelectedItems.Count == 1)
            {
                Cursor = Cursors.WaitCursor;

                try
                {
                    // Select original (DFE challenge only)
                    DFE originalChallenge = customTracksListView.SelectedItems[0].Tag as DFE;

                    if (originalChallenge != null)
                    {
                        // Select IGE/DFE file(s) to append
                        bool   isNotFinished = true;
                        string profileFolder = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Savegame), @"\", Program.ApplicationSettings.PlayerProfile);
                        string igeFolder     = string.Concat(profileFolder, LibraryConstants.FOLDER_IGE);

                        openFileDialog.Title            = _TITLE_PICK_TRACK_TO_MERGE;
                        openFileDialog.Filter           = GuiConstants.FILTER_DFE_IGE_FILES;
                        openFileDialog.InitialDirectory = igeFolder;

                        while (isNotFinished)
                        {
                            // File selection
                            DialogResult dr = openFileDialog.ShowDialog(this);

                            if (dr == DialogResult.OK)
                            {
                                // Appends waypoints to end of original challenge
                                DFE additionalTrack = TduFile.GetFile(openFileDialog.FileName) as DFE;

                                if (additionalTrack == null)
                                {
                                    throw new Exception("Unable to load custom track: " + openFileDialog.FileName);
                                }

                                // Creating new Waypoint data
                                originalChallenge.MergeCheckpoints(additionalTrack);
                            }

                            // Continue ?
                            dr = MessageBoxes.ShowQuestion(this, _QUESTION_CONTINUE_MERGE, MessageBoxButtons.YesNo);

                            if (dr == DialogResult.No)
                            {
                                isNotFinished = false;
                            }
                        }

                        // End, saving DFE track
                        originalChallenge.Save();

                        // Refresh
                        _RefreshCustomList();

                        StatusBarLogManager.ShowEvent(this, _STATUS_MERGE_OK);
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxes.ShowError(this, ex);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }