Inheritance: INotifyPropertyChanged
Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            DataLoader.LoadAvailableProjectsFromCsv();

            viewModel = new NewProjectViewModel();
            viewModel.OpenSlnFolderAfterCreation = true;

            SetInitialProjectLocation();
            //RemoteFileManager.Initialize();

            ProcessCommandLineArguments();
            

            UseDifferentNamespaceCheckBoxChanged(null, null);

            ((System.Windows.Controls.Control)WpfHost.Child).DataContext = viewModel;
        }
Exemplo n.º 2
0
        public NewProjectViewModel ToViewModel()
        {
            NewProjectViewModel toReturn = new NewProjectViewModel();

            toReturn.ProjectName = this.ProjectNameTextBox.Text;

            toReturn.UseDifferentNamespace = DifferentNamespaceCheckbox.Checked;

            toReturn.DifferentNamespace = DifferentNamespaceTextbox.Text;

            toReturn.CheckForNewVersions = CheckForNewVersionCheckBox.Checked;

            toReturn.ProjectType = ProjectTypeListBox.SelectedItem as PlatformProjectInfo;

            // todo - the logic for this is in Form1.cs and it should be in the VM
            toReturn.ProjectLocation = ProjectLocationTextBox.Text;
            

            toReturn.CreateProjectDirectory = CreateProjectDirectoryCheckBox.Checked;

            return toReturn;
        }
Exemplo n.º 3
0
        public static bool MakeNewProject(NewProjectViewModel viewModel)
        {


            string stringToReplace;
            string zipToUnpack;
            GetDefaultZipLocationAndStringToReplace(viewModel.ProjectType, out zipToUnpack, out stringToReplace);
            string fileToDownload = GetFileToDownload(viewModel);

            bool succeeded = true;

			#if !MAC
            if (NewProjectCreator.Managers.CommandLineManager.Self.OpenedBy != null && NewProjectCreator.Managers.CommandLineManager.Self.OpenedBy.ToLower() == "glue")
            {
                PlatformProjectInfo ppi = viewModel.ProjectType;

                if (!ppi.SupportedInGlue)
                {
                    succeeded = false;
                    MessageBox.Show("This project type is not supported in Glue.  You must launch the New Project Creator manually");
                }
            }
			#endif

            if (succeeded)
            {
                string unpackDirectory = viewModel.ProjectLocation;

                bool isFileNameValid = GetIfFileNameIsValid(viewModel, ref unpackDirectory);

                if(!isFileNameValid)
                {
                    succeeded = false;
                }
                else
                {
                    bool hasUserCancelled = false;

                    bool shouldTryDownloading;
                    zipToUnpack = GetZipToUnpack(viewModel, fileToDownload, ref hasUserCancelled, out shouldTryDownloading);

                    if(shouldTryDownloading)
                    {
                        // Checks for a newer version and downloads it if necessary
                        bool downloadSucceeded = DownloadFileSync(viewModel, zipToUnpack, fileToDownload);

                        if (!downloadSucceeded)
                        {
                            ShowErrorMessageBox(ref hasUserCancelled, ref zipToUnpack, "Error downloading the file.  What would you like to do?");
                        }
                    }


                    if (!hasUserCancelled)
                    {
                        try
                        {
                            Directory.CreateDirectory(unpackDirectory);
                        }
                        catch (UnauthorizedAccessException)
                        {
                            MessageBox.Show("The program does not have permission to create a directory at\n\n" + unpackDirectory + "\n\nPlease run as administrator mode");
                            succeeded = false;
                        }

                        if (succeeded)
                        {
                            if (!File.Exists(zipToUnpack))
                            {
                                System.Windows.Forms.MessageBox.Show("Could not find the template file:\n" + zipToUnpack);
                            }


                            succeeded = UnzipManager.UnzipFile(zipToUnpack, unpackDirectory);
                        }

                        if (succeeded)
                        {
                            RenameEverything(viewModel, stringToReplace, unpackDirectory);

                            CreateGuidInAssemblyInfo(unpackDirectory);

                            if (viewModel.OpenSlnFolderAfterCreation)
                            {
                                Process.Start(unpackDirectory);
                            }

                            System.Console.Out.WriteLine(unpackDirectory);

                        }
                    }
                }
            }

            return succeeded;
        }
Exemplo n.º 4
0
        private static string GetFileToDownload(NewProjectViewModel viewModel)
        {

            PlatformProjectInfo foundInstance = viewModel.ProjectType;

            if (foundInstance == null)
            {
                throw new NotImplementedException("You must first select a template");
            }
            else
            {
                return foundInstance.Url;
            }
        }
Exemplo n.º 5
0
        private static bool DownloadFileSync(NewProjectViewModel viewModel, string zipToUnpack, string fileToDownoad)
        {
            EmbeddedExecutableExtractor eee = EmbeddedExecutableExtractor.Self;

            eee.ExtractFile("FlatRedBall.Tools.dll");
            eee.ExtractFile("Ionic.Zip.dll");
            eee.ExtractFile("Ionic.Zlib.dll");
            string resultingLocation = eee.ExtractFile("FRBDKUpdater.exe");


            UpdaterRuntimeSettings urs = new UpdaterRuntimeSettings();
            urs.FileToDownload = fileToDownoad;
            urs.FormTitle = "Downloading " + viewModel.ProjectType.FriendlyName;

            if (string.IsNullOrEmpty(zipToUnpack))
            {
                throw new Exception("The zipToUnpack argument is null - it shouldn't be");
            }

            urs.LocationToSaveFile = zipToUnpack;

            string whereToSaveSettings =
                FileManager.UserApplicationDataForThisApplication + "DownloadInformation." + UpdaterRuntimeSettings.RuntimeSettingsExtension;

            urs.Save(whereToSaveSettings);

            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = resultingLocation;

            // The username for the user may have a space in it
            // so we need to have quotes around the path

            psi.Arguments = "\"" + whereToSaveSettings + "\"";


            Process process = Process.Start(psi);

            while (!process.HasExited)
            {
                System.Threading.Thread.Sleep(200);
            }
            bool succeeded = process.ExitCode == 0;


            return succeeded;
        }
Exemplo n.º 6
0
        private static bool GetIfFileNameIsValid(NewProjectViewModel viewModel, ref string unpackDirectory)
        {
            bool isFileNameValid = true;
            #region Check for spaces if creating a directory for the project

            if (viewModel.CreateProjectDirectory)
            {
                if (viewModel.ProjectName.Contains(" "))
                {
                    System.Windows.Forms.MessageBox.Show("Project names cannot contain spaces.");
                    isFileNameValid = false;
                }


                unpackDirectory = viewModel.CombinedProjectDirectory;
            }

            #endregion


            if (Directory.Exists(unpackDirectory))
            {
                MessageBox.Show("The directory " + unpackDirectory + " already exists");
                isFileNameValid = false;
            }
            return isFileNameValid;
        }
Exemplo n.º 7
0
        private static string GetZipToUnpack(NewProjectViewModel viewModel, string fileToDownload, ref bool hasUserCancelled, out bool shouldTryDownloading)
        {
            bool checkOnline = viewModel.CheckForNewVersions;
            string zipToUnpack = null;
            shouldTryDownloading = false;
            if (!string.IsNullOrEmpty(fileToDownload))
            {
                zipToUnpack = FileManager.UserApplicationDataForThisApplication + FileManager.RemovePath(fileToDownload);
            }

            if (zipToUnpack == null)
            {
                string message = "There is no zip file online for this template.  What would you like to do?";
                ShowErrorMessageBox(ref hasUserCancelled, ref zipToUnpack, message);
                checkOnline = false;
            }


            if (checkOnline)
            {
                if (string.IsNullOrEmpty(fileToDownload))
                {
                    string message = "Couldn't find this project online.  What would you like to do?";

                    ShowErrorMessageBox(ref hasUserCancelled, ref zipToUnpack, message);
                }
                else
                {
                    shouldTryDownloading = true;
                }
            }
            return zipToUnpack;
        }
Exemplo n.º 8
0
        private static void RenameEverything(NewProjectViewModel viewModel, string stringToReplace, string unpackDirectory)
        {
            RenameFiles(unpackDirectory, stringToReplace,
                viewModel.ProjectName);

            UpdateSolutionContents(unpackDirectory, stringToReplace,
                viewModel.ProjectName);

            // UpdateProjects does a simple "Replace" call, which should
            // happen before we do the stricter UpdateNamespace call below.
            // Otherwise, if the user changes the project name to something that contains
            // the original name (like "StarBlaster"), then UpdateProject will result in the
            // namespace being incorrect.
            UpdateProjects(unpackDirectory, stringToReplace,
                viewModel.DifferentNamespace);

            UpdateNamespaces(unpackDirectory, stringToReplace,
                viewModel.DifferentNamespace);

        }