Jump to content

Including Text Files in Application

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Question.
I've got a Text File of Instructions for a 3rd party hardware.
This File is only edited during Development, and never during run time, so I don't wish for the end user to be able to mess with the file.

The Text file is a list of about 360 Lines where each line is sent to the hardware.

Now I know I can just "Open" it as a file & send it to the hardware via its communication bus, but that would mean that they can "edit" the file.

Is their a way to have this text file just encoded in the app so that the app can read it like a string or something ?

The previous version had each line hand coded with a write statement.
I.E.

Write("config line1");

Write("config line2");

Write("config line3");

ect, for 360+ lines now, not that efficient.
(the file itself is edited with another application designed for the hardware scripting)

what I'm hoping to find is something like

    string[] configfile=magic pointer to file in memory;

    foreach (string currentline in configfile)

    {

      Write(currentline);

    }



#2
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
DOH:

I figured it out, sorry :)

string ConfigFile = MyProject.Properties.Resources.ConfigFile.ToString();

#3
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts

PGP_Protector said:

DOH:

I figured it out, sorry :)

string ConfigFile = MyProject.Properties.Resources.ConfigFile.ToString();

Well, if your text file is added to you project resources, the third party user is still able to change it. Maybe you should try to set this text file in resources a property that the file is embeded or something...

1. Why do you even want to prevent the user from changing the config file?

2. Is this text file going to be updated, modified or replaced anytime during the lifetime of application (whether by application developer or third party)?

3. Whether or not it is going to be updated, modified or replaced during the application's lifetime, you could write a class library project (DLL), which would contain a class with this configuration properties. This way, no user is able to read or modify configuration strings, but it is possible to replace this dll file with updated config strings.

Example follows:

1. Code for class "MyConfiguration" contained in class library project "ConfigManager":
namespace ConfigManager
{
    public class MyConfiguration
    {
        public const bool WINDOW_MAXIMIZED = true;
        public const bool RUN_IN_BACKGROUND = false;

        public const string ROOT_FOLDER = "C:\\MyAppRoot";
        public const string SERVER_IP_ADDR = "10.0.0.127";
    }
}

2. Class library usage (don't forget to set reference and using statement for this dll file):
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ConfigManager;

namespace ApplicationDesign
{
    class Program
    {
        static void Main(string[] args)
        {
            Directory.CreateDirectory(MyConfiguration.ROOT_FOLDER);
            //...
        }
    }
}


#4
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts

FlashM said:

Well, if your text file is added to you project resources, the third party user is still able to change it. Maybe you should try to set this text file in resources a property that the file is embeded or something...

1. Why do you even want to prevent the user from changing the config file?

It's not a Config file in the normal sense.
The Hardware runs its own scripting language that has to be loaded on startup, so I either code the full script in the main code or use their scripting package to develop the script that I can then send.
If the end user changes that script, well it will more than likely break the equipment.


FlashM said:

2. Is this text file going to be updated, modified or replaced anytime during the lifetime of application (whether by application developer or third party)?
During Development & debugging & certification, their will probabbly be a few changes, but after it's finalized, unless some bugs crop up, their will not be any other changes to the file.


FlashM said:

3. Whether or not it is going to be updated, modified or replaced during the application's lifetime, you could write a class library project (DLL), which would contain a class with this configuration properties. This way, no user is able to read or modify configuration strings, but it is possible to replace this dll file with updated config strings.
Thank you for that idea also, I'll look at that too.

#5
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
There are numerous ways how to create some sort of configuration file and configuration management. This was just an idea, how to create some sort of configuration file that can be updated or replaced with new ddl file during lifetime of application, but I don't think this is really the standard way.

If you don't need to hide configuration properties from user, you would normally use some xml file for that purpose.

#6
progcomputeach

progcomputeach

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
I found this to be a useful link for configuration:

Unraveling the Mysteries of .NET 2.0 Configuration - CodeProject

#7
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
Agree :-)

#8
progcomputeach

progcomputeach

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Theres another thread on here which gives sites for tutorials which is really good.