<commit_before>/**************************************************************************
**
** This file is part of the Qt VS Add-in
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (<EMAIL>)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;

namespace Nokia.QtProjectLib
{
    #region QMake Process

    class InfoDialog : Form
    {
        private Label label1 = null;
        private IContainer components = null;
        private ProgressBar progressBar1 = null;
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        public InfoDialog(string name)
        {
            this.label1 = new Label();
            this.components = new Container();
            this.progressBar1 = new System.Windows.Forms.ProgressBar();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(370, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = SR.GetString("QMakeProcess_OpenSolutionFromFile") + name;
            // 
            // progressBar1
            // 
            this.progressBar1.Location = new System.Drawing.Point(13, 28);
            this.progressBar1.Name = "progressBar1";
            this.progressBar1.Size = new System.Drawing.Size(369, 23);
            this.progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
            this.progressBar1.TabIndex = 1;
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(394, 67);
            this.MinimumSize = new System.Drawing.Size(402, 94);
            this.ControlBox = false;
            this.Controls.Add(this.progressBar1);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.ShowInTaskbar = false;
            this.Text = Resources.msgBoxCaption;
            this.StartPosition = FormStartPosition.CenterParent;

            this.ResumeLayout(false);
            this.PerformLayout();
        }

        public void CloseEventHandler()
        {
            this.Close();
        }
    }

    class QMake
    {
        public delegate void ProcessEventHandler();
        public event ProcessEventHandler CloseEvent;

        public delegate void ProcessEventHandlerArg(string data);
        public event ProcessEventHandlerArg PaneMessageDataEvent;

        private string file = null;
        private int errorValue = 0;
        private EnvDTE.DTE dteObject;
        private bool recursive = false;
        private VersionInformation qtVersionInformation;
        private static Process qmakeProcess = null;

        private static int stdOutputLines = 0;
        private static int errOutputLines = 0;
        private static StringBuilder stdOutput = null;
        private static StringBuilder errOutput = null;
        
        public int ErrorValue
        {
            get { return errorValue; }
        }

        public QMake(EnvDTE.DTE dte, string fileName, bool recursiveRun, VersionInformation vi)
        {
            dteObject = dte;
            file = fileName;
            recursive = recursiveRun;
            qtVersionInformation = vi;
        }

        public void RunQMake()
        {
            FileInfo fi = new FileInfo(file);
            string vcproj = HelperFunctions.RemoveFileNameExtension(fi);
#if VS2010
            vcproj += ".vcxproj";
#else
            vcproj += ".vcproj";
#endif

            string qmakeArgs = "-tp vc \"" + fi.Name + "\" ";

            if (recursive)
                qmakeArgs += "-recursive";
            else
                qmakeArgs += "-o \"" + vcproj + "\"";

            qmakeArgs += @" QMAKE_INCDIR_QT=$(QTDIR)\\include ";

            if (qtVersionInformation.qt4Version) {
                // We must clear QMAKE_LIBDIR_QT because qmake adds this path
                // to the additional library paths in the linker settings.
                qmakeArgs += "QMAKE_LIBDIR_QT=  ";
            }

            qmakeArgs += @"QMAKE_LIBDIR=$(QTDIR)\\lib "
                       + @"QMAKE_UIC=_(QTDIR)\\bin\\uic.exe "
                       + @"QMAKE_MOC=_(QTDIR)\\bin\\moc.exe "
                       + @"QMAKE_RCC=_(QTDIR)\\bin\\rcc.exe "
                       + @"QMAKE_QMAKE=$(QTDIR)\\bin\\qmake.exe";

            qmakeProcess = new System.Diagnostics.Process();
            qmakeProcess.StartInfo.CreateNoWindow = true;
            qmakeProcess.StartInfo.UseShellExecute = false;
            qmakeProcess.StartInfo.RedirectStandardError = true;
            qmakeProcess.StartInfo.RedirectStandardOutput = true;

            qmakeProcess.StartInfo.Arguments = qmakeArgs;
            qmakeProcess.StartInfo.FileName = qtVersionInformation.qtDir + "\\bin\\qmake";
            qmakeProcess.StartInfo.WorkingDirectory = fi.DirectoryName;

            // determine which vs version we are currently using and inform qmake about it
            string regPath = dteObject.Application.RegistryRoot + "\\Setup\\VC";
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath);
            if (key != null)<commit_msg>set QTDIR for the qmake process when importing .pro files<commit_after>/**************************************************************************
**
** This file is part of the Qt VS Add-in
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (<EMAIL>)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;

namespace Nokia.QtProjectLib
{
    #region QMake Process

    class InfoDialog : Form
    {
        private Label label1 = null;
        private IContainer components = null;
        private ProgressBar progressBar1 = null;
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        public InfoDialog(string name)
        {
            this.label1 = new Label();
            this.components = new Container();
            this.progressBar1 = new System.Windows.Forms.ProgressBar();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(370, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = SR.GetString("QMakeProcess_OpenSolutionFromFile") + name;
            // 
            // progressBar1
            // 
            this.progressBar1.Location = new System.Drawing.Point(13, 28);
            this.progressBar1.Name = "progressBar1";
            this.progressBar1.Size = new System.Drawing.Size(369, 23);
            this.progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
            this.progressBar1.TabIndex = 1;
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(394, 67);
            this.MinimumSize = new System.Drawing.Size(402, 94);
            this.ControlBox = false;
            this.Controls.Add(this.progressBar1);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.ShowInTaskbar = false;
            this.Text = Resources.msgBoxCaption;
            this.StartPosition = FormStartPosition.CenterParent;

            this.ResumeLayout(false);
            this.PerformLayout();
        }

        public void CloseEventHandler()
        {
            this.Close();
        }
    }

    class QMake
    {
        public delegate void ProcessEventHandler();
        public event ProcessEventHandler CloseEvent;

        public delegate void ProcessEventHandlerArg(string data);
        public event ProcessEventHandlerArg PaneMessageDataEvent;

        private string file = null;
        private int errorValue = 0;
        private EnvDTE.DTE dteObject;
        private bool recursive = false;
        private VersionInformation qtVersionInformation;
        private static Process qmakeProcess = null;

        private static int stdOutputLines = 0;
        private static int errOutputLines = 0;
        private static StringBuilder stdOutput = null;
        private static StringBuilder errOutput = null;
        
        public int ErrorValue
        {
            get { return errorValue; }
        }

        public QMake(EnvDTE.DTE dte, string fileName, bool recursiveRun, VersionInformation vi)
        {
            dteObject = dte;
            file = fileName;
            recursive = recursiveRun;
            qtVersionInformation = vi;
        }

        public void RunQMake()
        {
            FileInfo fi = new FileInfo(file);
            string vcproj = HelperFunctions.RemoveFileNameExtension(fi);
#if VS2010
            vcproj += ".vcxproj";
#else
            vcproj += ".vcproj";
#endif

            string qmakeArgs = "-tp vc \"" + fi.Name + "\" ";

            if (recursive)
                qmakeArgs += "-recursive";
            else
                qmakeArgs += "-o \"" + vcproj + "\"";

            qmakeArgs += @" QMAKE_INCDIR_QT=$(QTDIR)\\include ";

            if (qtVersionInformation.qt4Version) {
                // We must clear QMAKE_LIBDIR_QT because qmake adds this path
                // to the additional library paths in the linker settings.
                qmakeArgs += "QMAKE_LIBDIR_QT=  ";
            }

            qmakeArgs += @"QMAKE_LIBDIR=$(QTDIR)\\lib "
                       + @"QMAKE_UIC=_(QTDIR)\\bin\\uic.exe "
                       + @"QMAKE_MOC=_(QTDIR)\\bin\\moc.exe "
                       + @"QMAKE_RCC=_(QTDIR)\\bin\\rcc.exe "
                       + @"QMAKE_QMAKE=$(QTDIR)\\bin\\qmake.exe";

            qmakeProcess = new System.Diagnostics.Process();
            qmakeProcess.StartInfo.CreateNoWindow = true;
            qmakeProcess.StartInfo.UseShellExecute = false;
            qmakeProcess.StartInfo.RedirectStandardError = true;
            qmakeProcess.StartInfo.RedirectStandardOutput = true;

            qmakeProcess.StartInfo.Arguments = qmakeArgs;
            qmakeProcess.StartInfo.FileName = qtVersionInformation.qtDir + "\\bin\\qmake";
            qmakeProcess.StartInfo.WorkingDirectory = fi.DirectoryName;

            // We must set the QTDIR environment variable, because we're clearing QMAKE_LIBDIR_QT above.
            // If we do not set this, the Qt libraries will be QtCored.lib instead of QtCore4d.lib even
            // for shared builds.
            qmakeProcess.StartInfo.EnvironmentVariables["QTDIR"] = qtVersionInformation.qtDir;

            // determine which vs version we are currently using and inform qmake about it
            string regPath = dteObject.Application.RegistryRoot + "\\Setup\\VC";
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath);
            if (key != null)
{'fraction_non_alphanumeric': 0.11202958451163803, 'fraction_numerical': 0.010659125516641287, 'mean_word_length': 2.109107303877367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2873089', 'n_tokens_mistral': 3712, 'n_tokens_neox': 3447, 'n_words': 947}