Exemplo n.º 1
0
        private bool PrepareGameLaunch()
        {
            string sRootFolder = CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).GetValueString();
            string sGameFolder = CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString();

            // Check if game folder is not inside root folder
            if (CPathUtils.ExtractRelativeToRoot(sGameFolder) == sGameFolder)
            {
                MessageBoxResult res = MessageBox.Show(Properties.Resources.GameLauchCopyToRoot,
                                                       Properties.Resources.CommonNotice,
                                                       MessageBoxButton.OKCancel,
                                                       MessageBoxImage.Exclamation);

                if (res == MessageBoxResult.OK)
                {
                    string sFullTempDirPath = sRootFolder + "\\" + m_sGameTempDirName;
                    if (Directory.Exists(sFullTempDirPath))
                    {
                        Directory.Delete(sFullTempDirPath, true);
                    }

                    Directory.CreateDirectory(sFullTempDirPath);

                    CProcessUtils.CopyDirectory(sGameFolder, sFullTempDirPath);
                    SetGameFolderInSysCFG(sFullTempDirPath);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public void RemoveFileFromTracking(string sFilePath, EFileRoot root)
        {
            if (root == EFileRoot.eFR_CERoot)
            {
                // if we can extract the gamefolder from the root folder, add to game folder tracking
                // this means that the game folder is inside the root folder and doing
                // so avoid tracking one file with both lists
                if (CPathUtils.ExtractRelativeToGameFolder(sFilePath) != sFilePath)
                {
                    root = EFileRoot.eFR_GameFolder;
                }
            }
            switch (root)
            {
            case EFileRoot.eFR_CERoot:
            {
                m_trackedCERootFiles.Remove(CPathUtils.ExtractRelativeToRoot(sFilePath));
                DumpFilesToDisk(m_sCurrentRootTrackingListPath, EFileRoot.eFR_CERoot);
            } break;

            case EFileRoot.eFR_GameFolder:
            {
                m_trackedGameFolderFiles.Remove(CPathUtils.ExtractRelativeToGameFolder(sFilePath));
                DumpFilesToDisk(m_sCurrentGameTrackingListPath, EFileRoot.eFR_GameFolder);
            } break;

            default:
                throw new Exception("Invalid value for EFileRoot");
            }
        }
Exemplo n.º 3
0
        public bool IsRootValid(string sRootPath)
        {
            // TODO: Implement

            if (sRootPath == ESettingsStrings.Invalid)
            {
                return(false);
            }

            if (!CPathUtils.IsStringCEConform(sRootPath))
            {
                MessageBox.Show("Sorry, the directory contains non ASCII characters or whitespaces.\nThis will cause problems inside CE." +
                                "\nPlease use a path containing only numbers or letters from A-Z (a-z) and don't use spaces in your foldernames!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // LOCALIZE
                return(false);
            }


            string rcpath = sRootPath + CApplicationSettings.Instance.GetValue(ESettingsStrings.RCRelativePath).GetValueString();            //"\\Bin32\\rc\\rc.exe";

            if (!File.Exists(rcpath))
            {
                MessageBox.Show("Sorry, no rc.exe found!\n Make sure you have selected a CE root dir (contains Bin32, Bin64 e.t.c)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // LOCALIZE
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public void Init()
        {
            if (!Directory.Exists(".\\SourceTracker"))
            {
                Directory.CreateDirectory(".\\SourceTracker");
            }

            m_trackedCERootFiles      = new List <string>();
            m_trackedGameFolderFiles  = new List <string>();
            m_ignoredFiles            = new List <string>();
            m_ignoredFilesWacher      = new FileSystemWatcher();
            m_ignoredRegexList        = new List <Regex>();
            m_ignoredNegatedRegexList = new List <Regex>();

            m_ignoredFilesWacher.Path         = CPathUtils.GetFilePath(m_sIgnoredFilesListPath);
            m_ignoredFilesWacher.Filter       = "Ignorefiles.txt";
            m_ignoredFilesWacher.NotifyFilter = NotifyFilters.LastWrite;
            //m_ignoredFilesWacher.Changed += delegate { LoadIgnoredFilesList(); };

            m_lockingObject = new object();



            LoadIgnoredFilesList(CApplicationSettings.Instance.GetValue(ESettingsStrings.CheckIgnoredRegexSanityOnStartup).GetValueBool());
            LoadFileTrackingList(m_sCurrentRootTrackingListPath, EFileRoot.eFR_CERoot);
            LoadFileTrackingList(m_sCurrentGameTrackingListPath, EFileRoot.eFR_GameFolder);
        }
Exemplo n.º 5
0
        private bool ProcessRequest(FileInfo info)
        {
            string sNewFile = saveFileTextBox.Text + "\\" + info.Name;

            if (copyCheckbox.IsChecked == true)
            {
                if (CPathUtils.IsStringCEConform(saveFileTextBox.Text))
                {
                    CProcessUtils.CopyFile(info.FullName, sNewFile, false);
                }
                else
                {
                    return(false);
                }

                if (rcCheckbox.IsChecked == true)
                {
                    FileInfo newFile = new FileInfo(sNewFile);
                    CProcessUtils.RunRC(newFile);
                }
            }
            else
            {
                if (rcCheckbox.IsChecked == true)
                {
                    CProcessUtils.RunRC(info);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Displays a text box at the currently selected tree item's position.
        /// </summary>
        /// <param name="callbackOnPressedEnter">Called when enter is pressed while the text box has focus</param>
        private static void ShowAdHocMessageBox(Func <TextBox, int> callbackOnPressedEnter)
        {
            TextBox box = new TextBox();



            box.SetValue(Grid.ColumnProperty, 1);
            box.Height = 20;


            TreeViewItem selected = m_targetTreeView.SelectedItem as TreeViewItem;;

            Point translation = selected.TranslatePoint(new Point(0, 0), m_targetTreeView);
            Point extend      = selected.TranslatePoint(new Point(selected.Width, selected.Height), m_targetTreeView);

            box.RenderTransform = new System.Windows.Media.TranslateTransform(translation.X, translation.Y);
            box.Width           = selected.Width;



            Grid parentGrid = m_targetTreeView.Parent as Grid;


            if (parentGrid != null)
            {
                box.KeyDown += delegate(object sender, System.Windows.Input.KeyEventArgs e)
                {
                    if (e.Key == System.Windows.Input.Key.Enter)
                    {
                        if (CPathUtils.IsStringCEConform(box.Text))
                        {
                            parentGrid.Children.Remove(box);
                            callbackOnPressedEnter(box);
                        }
                        else
                        {
                            box.Text = "";
                        }
                    }
                    else if (e.Key == System.Windows.Input.Key.Escape)
                    {
                        parentGrid.Children.Remove(box);
                    }
                };

                box.LostFocus += delegate
                {
                    parentGrid.Children.Remove(box);
                };

                parentGrid.Children.Add(box);

                box.Focus();
            }
        }
Exemplo n.º 7
0
 public bool IsFileTracked(string sFilePath, out EFileRoot root)
 {
     if (CPathUtils.ExtractRelativeToGameFolder(sFilePath) != sFilePath)
     {
         root = EFileRoot.eFR_GameFolder;
         return(m_trackedGameFolderFiles.Contains(CPathUtils.ExtractRelativeToGameFolder(sFilePath)));
     }
     else
     {
         root = EFileRoot.eFR_CERoot;
         return(m_trackedCERootFiles.Contains(CPathUtils.ExtractRelativeToRoot(sFilePath)));
     }
 }
Exemplo n.º 8
0
        void OnSetGameFolderClicked(object sender, RoutedEventArgs e)
        {
            // DONE_FIXME: Don't override when previous valid and canceled!
            //ValidateGameFolder();
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
            dialog.Description = "Please specify the game folder to be used for the current CE config (can be anywhere, must be CE conform)";             // LOCALIZE

            if (CApplicationSettings.Instance.IsRootPathSet() == true)
            {
                dialog.SelectedPath = CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).GetValueString() + "\\Bin32";
            }

            System.Windows.Forms.DialogResult res;

            do
            {
                res = dialog.ShowDialog();
            }while (!CPathUtils.IsStringCEConform(dialog.SelectedPath) && res != System.Windows.Forms.DialogResult.Cancel);


            if (res != System.Windows.Forms.DialogResult.Cancel)
            {
                string sOldPath = CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString();
                CApplicationSettings.Instance.SetValue(new CSetting(ESettingsStrings.GameFolderPath, dialog.SelectedPath));
                CApplicationSettings.Instance.SaveApplicationSettings();
                OnGameFolderChanged(dialog.SelectedPath, sOldPath);
                HintGameFolderValid(true);
            }
            else
            {
                // TODO: Revisit, if path doesn't exist, set to invalid
                if (CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString() != ESettingsStrings.Invalid)
                {
                    return;
                }

                MessageBox.Show("Setting game folder to the default (the current root's GameSDK folder!",                 // LOCALIZE
                                "Aborted!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                string root = (string)CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).Value;

                string path = root + "\\GameSDK";

                HintGameFolderValid(Directory.Exists(path));

                CApplicationSettings.Instance.SetValue(new CSetting(ESettingsStrings.GameFolderPath, path));
            }
        }
Exemplo n.º 9
0
        static void OnContextOpenInExplorerClicked(object sender, RoutedEventArgs args)
        {
            if (m_targetTreeView.SelectedItem != null)
            {
                DirectoryTreeItem item    = m_targetTreeView.SelectedItem as DirectoryTreeItem;
                string            dirPath = "";

                if (item.IsDirectory)
                {
                    dirPath = item.FullPath;
                }
                else
                {
                    dirPath = CPathUtils.GetFilePath(item.FullPath);
                }

                Process proc = new Process();
                proc.StartInfo = new ProcessStartInfo("explorer", dirPath);
                proc.Start();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Checks whether sPath is CE conform and actually contains a file name
        /// </summary>
        /// <param name="sPath"></param>
        /// <returns>True if valid, else false</returns>
        private bool ValidateFilePath(string sPath)
        {
            // Need to check for a valid filename because user can enter stuff in the textbox itself

            int            dotPos = DesiredSavePath.LastIndexOf('.');
            int            dirPos = DesiredSavePath.LastIndexOf('\\');
            ComboBoxItem   item   = dccProgramDropdown.SelectedItem as ComboBoxItem;
            CDCCDefinition prog   = CApplicationSettings.Instance.GetDCCProgram(item.Content as string);

            if ((dotPos < dirPos && dotPos != -1) || dirPos == DesiredSavePath.Length - 1)
            {
                MessageBox.Show("Please specify a valid filname with extension", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            // It's valid but doesn't have an extension
            // Irrelevant since the name is only used for naming anyway

            /*if (dotPos == -1)
             * {
             *
             *
             *      DesiredSavePath += "." + prog.FileExtension;
             * }
             * else
             * {
             *      // Check for the correct extension
             *      string extension = DesiredSavePath.Substring(dotPos + 1, DesiredSavePath.Length - dotPos -1);
             *
             *      if (extension != prog.FileExtension)
             *      {
             *              string newPath = DesiredSavePath.Substring(0, dotPos + 1) + prog.FileExtension;
             *      }
             * }
             */


            return(CPathUtils.IsStringCEConform(sPath));
        }
Exemplo n.º 11
0
        public void ValidateGameFolder()
        {
            string gameFolder = (string)(CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).Value);

            bool ok     = CPathUtils.IsStringCEConform(gameFolder);
            bool exists = Directory.Exists(gameFolder);

            while (CPathUtils.IsStringCEConform(gameFolder) == false || Directory.Exists(gameFolder) == false)
            {
                MessageBoxResult res = MessageBox.Show("Please specify a gamefolder!", "Important", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);                 // LOCALIZE
                if (res != MessageBoxResult.Cancel)
                {
                    OnSetGameFolderClicked(null, null);
                    gameFolder = (string)(CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).Value);

                    if (gameFolder.Contains(ESettingsStrings.Invalid))
                    {
                        HintGameFolderValid(true);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Setting game folder to the default (the current root's GameSDK) folder!",                     // LOCALIZE
                                    "Aborted!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    string root = (string)CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).Value;

                    string path = root + "\\GameSDK";

                    HintGameFolderValid(Directory.Exists(path));
                    CApplicationSettings.Instance.SetValue(new CSetting(ESettingsStrings.GameFolderPath, path));
                    return;
                }
            }

            HintGameFolderValid(true);
        }
Exemplo n.º 12
0
        private void ExpandMacrosByte(string filePath)
        {
            FileInfo info = new FileInfo(filePath);

            string fileContent = File.ReadAllText(filePath);

            if (fileContent.Contains(m_sRootPathMacro) ||
                fileContent.Contains(m_sGameFolderMacro) ||
                fileContent.Contains(m_sFileNameMacro) ||
                fileContent.Contains(m_sFileMacro) ||
                fileContent.Contains(m_sFolderMacro))
            {
                string ceRoot       = CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).GetValueString();
                string ceGameFolder = CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString();

                fileContent = fileContent.Replace(m_sRootPathMacro, ceRoot);
                fileContent = fileContent.Replace(m_sGameFolderMacro, ceGameFolder);
                fileContent = fileContent.Replace(m_sFileNameMacro, CPathUtils.GetFilename(info.Name));
                fileContent = fileContent.Replace(m_sFileMacro, info.FullName);
                fileContent = fileContent.Replace(m_sFolderMacro, info.Directory.FullName);

                File.WriteAllText(filePath, fileContent);
            }
        }
Exemplo n.º 13
0
        void OnOKClicked(object sender, RoutedEventArgs e)
        {
            string path = fileTextBox.Text;

            string[] paths = path.Split(';');
            foreach (string filePath in paths)
            {
                if (String.IsNullOrWhiteSpace(filePath))
                {
                    continue;
                }

                string finalPath = filePath;
                if (!finalPath.Contains("."))
                {
                    CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonNoFileNameSpecified);
                    return;
                }

                FileInfo info = new FileInfo(finalPath);

                if (info.Extension != CSourceTracker.FileExtension)
                {
                    finalPath = CPathUtils.ChangeExtension(finalPath, CSourceTracker.FileExtension);
                }

                if (!info.Directory.Exists)
                {
                    Directory.CreateDirectory(info.DirectoryName);
                }

                EFileRoot root;
                bool      bDoBoth = false;

                if (affectionComboBox.SelectedIndex == 0)
                {
                    root = EFileRoot.eFR_CERoot;
                }
                else if (affectionComboBox.SelectedIndex == 1)
                {
                    root = EFileRoot.eFR_GameFolder;
                }
                else
                {
                    root    = EFileRoot.eFR_CERoot;
                    bDoBoth = true;
                }

                switch (m_mode)
                {
                case EMode.eMO_Import:
                {
                    EFileRoot targetRoot = CSourceTracker.Instance.GetTrackingFileAffection(finalPath);
                    if (!bDoBoth && targetRoot != root)
                    {
                        CUserInteractionUtils.ShowErrorMessageBox(Properties.ImportExportResources.AffectionMissmatch);
                        return;
                    }

                    CSourceTracker.Instance.ImportTrackingList(finalPath, CSourceTracker.Instance.GetTrackingFileAffection(finalPath));
                }
                break;

                case EMode.eMO_Export:
                {
                    if (!bDoBoth)
                    {
                        CSourceTracker.Instance.ExportTrackingFile(finalPath, root);
                    }
                    else
                    {
                        string name        = finalPath;
                        string noExtension = CPathUtils.RemoveExtension(name);
                        string rootFile    = noExtension;
                        string gameFile    = noExtension;
                        if (!rootFile.Contains("_Root"))
                        {
                            rootFile += "_Root";
                        }
                        if (!gameFile.Contains("_Game"))
                        {
                            gameFile += "_Game";
                        }



                        CSourceTracker.Instance.ExportTrackingFile(rootFile + CSourceTracker.FileExtension, EFileRoot.eFR_CERoot);
                        CSourceTracker.Instance.ExportTrackingFile(gameFile + CSourceTracker.FileExtension, EFileRoot.eFR_GameFolder);
                    }
                }
                break;

                case EMode.eMO_Move:
                {
                    if (!bDoBoth)
                    {
                        CSourceTracker.Instance.MoveTrackedFiles(finalPath, root);
                    }
                    else
                    {
                        CSourceTracker.Instance.MoveTrackedFiles(finalPath, EFileRoot.eFR_CERoot);
                        CSourceTracker.Instance.MoveTrackedFiles(finalPath, EFileRoot.eFR_GameFolder);
                    }
                }
                break;

                default:
                    throw new Exception("Invalid value for EMode");
                }
            }

            Close();
        }
Exemplo n.º 14
0
        static int RenameTreeEntry(TextBox box)
        {
            // DONE_TODO: Account for extension being typed already...
            DirectoryTreeItem selectedItem = m_targetTreeView.SelectedItem as DirectoryTreeItem;

            try
            {
                if (selectedItem.IsDirectory)
                {
                    string newPath = selectedItem.FullPath.Substring(0, selectedItem.FullPath.LastIndexOf('\\')) + '\\' + box.Text;
                    //Directory.Move(selectedItem.FullPath, newPath);
                    FileSystem.RenameDirectory(selectedItem.FullPath, newPath);
                }
                else
                {
                    var fileInfo = new FileInfo(selectedItem.FullPath);

                    string sNewExtension = CPathUtils.GetExtension(box.Text);

                    if (sNewExtension != box.Text && sNewExtension != fileInfo.Extension.TrimStart('.'))
                    {
                        var res = MessageBox.Show(Properties.Resources.FEConfirmChangeExtension,
                                                  Properties.Resources.CommonNotice,
                                                  MessageBoxButton.YesNo,
                                                  MessageBoxImage.Question);

                        if (res != MessageBoxResult.Yes)
                        {
                            sNewExtension = fileInfo.Extension.TrimStart('.');
                        }
                    }
                    else
                    {
                        if (sNewExtension == box.Text)
                        {
                            sNewExtension = fileInfo.Extension.TrimStart('.');
                        }
                    }
                    string filename = CPathUtils.RemoveExtension(CPathUtils.GetFilename(box.Text));
                    FileSystem.RenameFile(selectedItem.FullPath, filename + "." + sNewExtension);
                }
            }
            catch (Exception e)
            {
                if (e is ArgumentException ||
                    e is UnauthorizedAccessException ||
                    e is IOException)
                {
                    CUserInteractionUtils.ShowErrorMessageBox(e.Message);
                }
                else
                {
                    throw;
                }
            }


            var mainWindow = Application.Current.MainWindow as Window1;

            if (mainWindow != null)
            {
                // Not elegant but all the error checking is done in these methods
                // no sense in writing them again
                mainWindow.ValidateRootPath();
                mainWindow.ValidateGameFolder();
            }

            //selectedItem = selectedItem.GetParentSave() as DirectoryTreeItem;
            //selectedItem.Items.Clear();
            //TraverseDirectory(new DirectoryInfo(selectedItem.FullPath), ref selectedItem);

            return(0);
        }
Exemplo n.º 15
0
        private bool CheckIgnoredFilesSanity()
        {
            var filesList = new List <string>();


            string sRoot = CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).GetValueString();
            string sGame = CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString();

            GetFilesInDirectory(sRoot, filesList);

            // If we can't extract the game folder from the root folder, it is in a different place
            // and needs to be checked, too.
            if (CPathUtils.ExtractRelativeToRoot(sGame) == sGame)
            {
                GetFilesInDirectory(sGame, filesList);
            }

            bool[] oIgnoredBool    = new bool[m_ignoredRegexList.Count];
            bool[] oNotIgnoredBool = new bool[m_ignoredNegatedRegexList.Count];

            for (int i = 0; i < m_ignoredNegatedRegexList.Count; ++i)
            {
                var currentRegex = m_ignoredNegatedRegexList[i];

                foreach (string file in filesList)
                {
                    if (currentRegex.IsMatch(file))
                    {
                        oNotIgnoredBool[i] = true;
                        break;
                    }
                }
            }

            for (int i = 0; i < m_ignoredRegexList.Count; ++i)
            {
                var currentRegex = m_ignoredRegexList[i];

                foreach (string file in filesList)
                {
                    if (currentRegex.IsMatch(file))
                    {
                        oIgnoredBool[i] = true;
                        break;
                    }
                }
            }

            bool bIsSane = true;


            for (int i = 0; i < oIgnoredBool.Length; ++i)
            {
                var ignoredSane = oIgnoredBool[i];
                if (!ignoredSane)
                {
                    LogSanityWarning(m_ignoredRegexList[i].ToString());
                    bIsSane = false;
                }
            }


            for (int i = 0; i < oNotIgnoredBool.Length; ++i)
            {
                var notIgnoredSane = oNotIgnoredBool[i];

                if (!notIgnoredSane)
                {
                    LogSanityWarning(m_ignoredNegatedRegexList[i].ToString());
                    bIsSane = false;
                }
            }

            return(bIsSane);
        }
Exemplo n.º 16
0
        public bool AddFileToTracking(string sFilePath, EFileRoot root, bool bBypassIgnoreList = false)
        {
            bool bIsAdded = false;


            lock (m_trackedCERootFiles)
            {
                if (root == EFileRoot.eFR_CERoot)
                {
                    // if we can extract the gamefolder from the root folder, add to game folder tracking
                    // this means that the game folder is inside the root folder and doing
                    // so avoid tracking one file with both lists
                    if (CPathUtils.ExtractRelativeToGameFolder(sFilePath) != sFilePath)
                    {
                        root = EFileRoot.eFR_GameFolder;
                    }
                }


                switch (root)
                {
                case EFileRoot.eFR_CERoot:
                {
                    string relativePath = CPathUtils.ExtractRelativeToRoot(sFilePath);
                    if (!m_trackedCERootFiles.Contains(relativePath) && (bBypassIgnoreList || !ShouldIgnorePath(sFilePath)))
                    {
                        m_trackedCERootFiles.Add(relativePath);
                        bIsAdded = true;
                    }
                } break;

                case EFileRoot.eFR_GameFolder:
                {
                    string relativePath = CPathUtils.ExtractRelativeToGameFolder(sFilePath);
                    if (!m_trackedGameFolderFiles.Contains(relativePath) && (bBypassIgnoreList || !ShouldIgnorePath(sFilePath)))
                    {
                        m_trackedGameFolderFiles.Add(relativePath);
                        bIsAdded = true;
                    }
                } break;

                default:
                    throw new Exception("Invalid value for EFileRoot");
                }
            }

            if (bIsAdded)
            {
                switch (root)
                {
                case EFileRoot.eFR_CERoot:
                {
                    DumpFilesToDisk(m_sCurrentRootTrackingListPath, EFileRoot.eFR_CERoot);
                } break;

                case EFileRoot.eFR_GameFolder:
                {
                    DumpFilesToDisk(m_sCurrentGameTrackingListPath, EFileRoot.eFR_GameFolder);
                } break;
                }
            }
            return(bIsAdded);
        }