Update Revision

Interested in developing new plug-ins? Got one to share? Post here!
zchris
Posts: 92
Joined: Wed Feb 23, 2005 3:16 am
Location: Austria

Update Revision

Postby zchris » Thu Mar 03, 2005 6:54 am

InstallAware has an option to update the revision on every build - unfortunately this does not work for commandline builds.

As a workaround I'm using this small tool:

http://www.camelot.co.at/files/dist/UpdateRevision.zip

Just call it with UpdateRevision.exe pathTo\\Project.mpr


Here's the source:

using System;
using System.IO;
using System.Text;

namespace UpdateRevision
{

class Class1
{

[STAThread]
static void Main(string[] args)
{
if (args.Length<1)
{
Console.WriteLine("Specify a mpr file.");
return;
}

string name=args[0];
string text;

Console.WriteLine("Processing file {0}", name);

using (StreamReader input=new StreamReader(name, Encoding.ASCII))
text=input.ReadToEnd();

int idx=text.IndexOf("{"); // product code
if (idx<0) throw new Exception("Invalid file (no product).");
idx=text.IndexOf("{", idx+1); // revision code
if (idx<0) throw new Exception("Invalid file (no revision).");
if (text.IndexOf("{", idx+1)>=0) throw new Exception("Invalid file (unknown guid).");

idx++;
string oldGuid=text.Substring(idx, 36), newGuid=Guid.NewGuid().ToString();

Console.WriteLine("Old Revision: {0}", oldGuid);
Console.WriteLine("New Revision: {0}", newGuid);

string text2=text.Substring(0, idx);
text2+=newGuid;
text2+=text.Substring(idx+36);

File.Copy(name, name+".revbak", true);

using (StreamWriter output=new StreamWriter(name, false, Encoding.ASCII))
output.Write(text2);

Console.WriteLine("done.");
}
}
}

sinan
Site Admin
Posts: 1020
Joined: Sat Nov 13, 2004 8:12 am
Contact:

Postby sinan » Thu Mar 03, 2005 5:39 pm

Thanks for this great tool! We did receive a lot of requests for this feature though, so InstallAware 2005 allows automatic change of the build code from command line builds:

Code: Select all

miabuild.exe ... /r

Note that the one caveat for the above procedure is that the changed revision code does not update the project file...it just uses a new revision code for that build. So there might be cases wherein the UpdateRevision tool may come in handy! Many thanks.

Guest

Postby Guest » Fri Mar 04, 2005 3:11 am

I wrote this for InstallAware 3 -- I thought I checked the dox on the new 2005 version but I must have been blind to not see the /r switch :?

JeffTucker
Posts: 62
Joined: Thu Mar 19, 2009 11:07 am
Contact:

Great stuff for miabuild automation! Fixed for IA8

Postby JeffTucker » Thu Jun 18, 2009 10:54 am

I tried this on a IA 8 project and it had a couple of bugs. Here is the corrected code:

[STAThread]
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Please specify a InstallAware project (.MPR) file.");
return;
}

string name = args[0];
string text;

Console.WriteLine("Processing file {0}", name);

using (StreamReader input = new StreamReader(name, Encoding.ASCII))
text = input.ReadToEnd();

int idx = text.IndexOf("{"); // product code
if (idx < 0)
throw new Exception("Invalid file (no product).");
idx = text.IndexOf("{", idx + 1); // revision code
if (idx < 0)
throw new Exception("Invalid file (no GUID).");
// The third one found is our revision in reality.
idx = text.IndexOf("{", idx + 1);
if (idx < 0)
throw new Exception("Invalid file (unknown revision).");

idx++;
string oldGuid = text.Substring(idx, 36);
string newGuid = Guid.NewGuid().ToString();

Console.WriteLine("Old Revision was: {0}", oldGuid);
Console.WriteLine("New Revision is: {0}", newGuid);

string text2 = text.Substring(0, idx);
text2 += newGuid;
text2 += text.Substring(idx + 36);

File.Copy(name, name + ".revbak", true);

using (StreamWriter output = new StreamWriter(name, false, Encoding.ASCII))
output.Write(text2);

Console.WriteLine("done.");

}

I don't know what meaning that second GUID has, but the third one is the revision for sure. The other code always exceptioned out.

Perhaps the older version of IA had a different file layout?
Fiddling with technology


Return to “Plug-In Development”

Who is online

Users browsing this forum: No registered users and 40 guests