Hey guys,
Recently I have been working on an addon which allows for asteroid mining.
One of the issues I have is being able to determine what models I am using so I can provide documentation on what addons are required in order for the addon to work.
To solve this I whipped up a simple C# program which illiterates through folders looking through .lua files to determine if there is a reference to .mdl and then listing it on a listbox (and checking for duplicates)
Once done you press "Spew Items" and it copies it to the textbox bellow with one model per line.
You can do what you want with the code on the provisio that you release the source code for any releases (knowledge like this belongs to the people) and give attribution for any of my bits that I have used.
Without any further ado...
This was developed under Microsoft Visual Studio 2010 in C# using the Microsoft .NET Framework 3.0. The intended audience for this code is developers and as such essential idiot checks are missing. Don't whinge at me if your an idiot and click find folder with a null or invalid path...
Once I work out indexing etc I will release a more user friendly version.
form1.cs
[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace GarrysModDependancyFinder
{
public partial class Form1 : Form
{
private delegate void ThreadSafeCall(String msg);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
private void RecurseFolder(String path)
{
String[] files = Directory.GetFiles(path);
foreach (String file in files)
{
if (file.Contains(".lua"))
{
ProcessFile(file);
}
Application.DoEvents();
}
String[] folders = Directory.GetDirectories(path);
foreach (String folder in folders)
{
RecurseFolder(folder);
Application.DoEvents();
}
}
private void ProcessFile(String file)
{
StreamReader fs = new StreamReader(file);
while (fs.EndOfStream == false)
{
String line = fs.ReadLine();
if (line.Contains(".mdl"))
{
handleLine(line);
}
}
fs.Close();
}
private void handleLine(String line)
{
line = line.Substring(0, line.IndexOf(".mdl\"")+4);
line = line.Substring(line.LastIndexOf("\"")+1);
if(!listBox1.Items.Contains(line))
AppendList(line);
}
private void AppendList(String item)
{
if (this.listBox1.InvokeRequired)
{
ThreadSafeCall tsc = new ThreadSafeCall(AppendList);
this.listBox1.Invoke(tsc, item);
}
else
{
this.listBox1.Items.Add(item);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
RecurseFolder(textBox1.Text);
}
private void button3_Click(object sender, EventArgs e)
{
textBox2.Text = "";
foreach (String item in listBox1.Items)
{
textBox2.Text += item + "\r\n";
}
}
}
}
[/code]
form1.designer.cs
[code]
namespace GarrysModDependancyFinder
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.button2 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.button3 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Path";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(54, 10);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(224, 20);
this.textBox1.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(284, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "Find folder";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(365, 8);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(137, 23);
this.button2.TabIndex = 3;
this.button2.Text = "List all refences to mdls";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(23, 54);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(578, 290);
this.listBox1.TabIndex = 4;
//
// button3
//
this.button3.Location = new System.Drawing.Point(516, 361);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 5;
this.button3.Text = "Spew items to text area";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(33, 358);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
If even you should zip up the whole project, anyways, this should rather go to the lua main section or the programming forum since its not a dll.
[QUOTE=Wizard of Ass;32587387]If even you should zip up the whole project, anyways, this should rather go to the lua main section or the programming forum since its not a dll.[/QUOTE]
Reason I put it here is it's the most relevant place for it. In the lua section it's not the right spot because it's C#.
Programming forum maybe. bit late for that though now :(
Sorry, you need to Log In to post a reply to this thread.