Example #1
0
        /// <summary>
        /// Write the C++ source code based on the parsed resource information.
        /// </summary>
        /// <param name="theOutDir">Directory to write the C++ files (current dir, if emtpy).</param>
        /// <param name="theOutFileName">Name of the C++ files without extension.</param>
        /// <param name="theFunctionPrefix">A optional function prefix.</param>
        /// <returns>False in case of any error, otherwise true.</returns>
        public bool WriteSourceCode(String theOutDir, String theOutFileName, String theFunctionPrefix)
        {
            mFunctionPrefix = theFunctionPrefix;

            if (theOutDir == "")
            {
                mErrorString = "Please specify Output Directory!";
                return(false);
            }

            if (theOutFileName == "")
            {
                mErrorString = "Please specify Output File Name!";
                return(false);
            }

            try
            {
                //////////////////////////////////////////////////////////////////////////
                // create path and file names
                //////////////////////////////////////////////////////////////////////////
                theOutDir = Common.AddTrailingSlash(theOutDir);
                theOutDir = Common.GetStandardFileName(theOutDir);

                String aHeaderName = theOutDir + theOutFileName + ".h";
                String aSourceName = theOutDir + theOutFileName + ".cpp";

                // open stream for header file
                try
                {
                    aStreamWriter = new StreamWriter(aHeaderName);
                }
                catch (ArgumentException aException)
                {
                    mErrorString = "Unable to open stream: " + aHeaderName + " " + aException.Message;

                    return(false);
                }

                mOutputForm.WriteLine("Writing header file: " + aHeaderName);
                Application.DoEvents();

                // write header file
                WriteHeaderFile(theOutFileName);

                aStreamWriter.Close();
                aStreamWriter.Dispose();

                // open stream for source file
                try
                {
                    aStreamWriter = new StreamWriter(aSourceName);
                }
                catch (ArgumentException aException)
                {
                    mErrorString = "Unable to open stream: " + aSourceName + " " + aException.Message;

                    return(false);
                }

                mOutputForm.WriteLine("Writing source file: " + aSourceName);
                Application.DoEvents();

                // write source file
                WriteSourceFile(theOutFileName);

                aStreamWriter.Close();
                aStreamWriter.Dispose();
            }
            catch (Exception aException)
            {
                mErrorString += aException.Message;

                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Parse common resource attributes, save the data in resource dictionary and variable list.
        /// </summary>
        /// <param name="theType">The resource type.</param>
        /// <returns>False if attribute path is missing or the element already exists, otherwise true.</returns>
        private bool ParseCommonResource(ResType theType)
        {
            String aPath = aXMLReader.GetAttribute("path");
            String anId  = aXMLReader.GetAttribute("id");
            String aTempString;

            if (aPath == null)
            {
                mErrorString = "No path specified";
                if (anId != null)
                {
                    mErrorString += " ID: " + anId;
                }

                return(false);
            }

            if (anId == null)
            {
                anId = mDefaultIdPrefix + Common.GetFileName(aPath, true);
            }
            else
            {
                anId = mDefaultIdPrefix + anId;
            }

            mOutputForm.WriteLine("Parsing Element " + anId);
            Application.DoEvents();

            AddFile(aPath);

            if (theType == ResType.Image)
            {
                aTempString = aXMLReader.GetAttribute("alphaimage");

                if (aTempString != null)
                {
                    AddFile(aTempString);
                }

                aTempString = aXMLReader.GetAttribute("alphagrid");

                if (aTempString != null)
                {
                    AddFile(aTempString);
                }
            }

            BaseRes aRes = new BaseRes();

            aRes.mType = theType;
            aRes.mId   = anId;

            aTempString = aXMLReader.GetAttribute("alias");

            if (aTempString != null)
            {
                aRes.mAlias.Add(mDefaultIdPrefix + aTempString);
            }

            for (ushort i = 0; i < MAX_ALIASES; i++)
            {
                aTempString = aXMLReader.GetAttribute("alias" + i.ToString());

                if (aTempString != null)
                {
                    aRes.mAlias.Add(mDefaultIdPrefix + aTempString);
                }
            }

            try
            {
                mCurrentResGroup.Add(anId, aRes);
            }
            catch (ArgumentException)
            {
                mErrorString = "An element with Key = " + anId + " already exists.";
                return(false);
            }

            // save the resource information for the codewriter
            mVariableList.Add(aRes);

            return(true);
        }