Deployment of application with sound effects and txt document included - windows

I have made an simple application which uses few sound effects and .txt document for storing some info(those files are stored into my projects bin/Debug directory).The app works fine on my PC, but when I run the .exe file on other computer, it works until the sound or .txt file is necessary(then is gives me a warning message telling that sound or .txt file isn't reachable).
How can I solve this problem, i mean, what should I do to make my app work properly on other PC's as well.Thanks!
Edit:
Here it the code which uses only sound effects(i'm changing them, so there are more than one sound)
{
public partial class GameScreen : Form
{
bool sound;
string sound1;
string sound2;
string sound3;
SoundPlayer sp1;
public GameScreen(string PlayerName)
{
InitializeComponent();
sound1 = "Air_Horn.wav";
sound2 = "TaDam.wav";
sound3 = "Bonus.wav";
sp1 = new SoundPlayer(sound1);
sound = true;
}
private void GameScreen_Load(object sender, EventArgs e)
{
if (sound == true)sp1.Play();
}
}
}
and here is the code using sound effects and .txt document:
{
public partial class VictoryForm : Form
{
SoundPlayer sp2;
string results;
bool sound_eff;
public VictoryForm(string statistics, bool _sound)
{
InitializeComponent();
sp2 = new SoundPlayer("Cheering3.wav");
results = statistics;
sound_eff = _sound;
}
private void VictoryForm_Load(object sender, EventArgs e)
{
if (sound_eff == true) sp2.Play();
}
private void VictoryForm_FormClosing(object sender, FormClosingEventArgs e)
{
StreamWriter sw = new StreamWriter("Results.txt", true);
sw.WriteLine(results);
sw.Close();
}
}
}

Sounds like you a) have not copied your texts or sound to the other computer or b) use wrong path to them. To be sure, print out the full path to the text or sound files and check if the intended files are really there. I bet they are not. ...
Btw, the contructor of StreamWriter says about its arguments: path = "The complete file path to write to", but your "Result.txt" is not a full path.

Related

Unable to Export Sqlite database from SpecialFolder.ApplicationData to SD Card Xamarin Forms

I am currently developing an app that uses the sqlite-net database. I am trying to copy/export the database to my SD Card. When I run the code I get a System.NullRefrenceException: 'Object reference not set to an instance of an object.'
I have tried several solutions but I always get the same exception. The issues occurs at the System.IO.File.WriteAllBytes(fileCopyName, bytes); Please help.
private void CopyDBButton_Clicked(object sender, EventArgs e)
{
var basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var finalPath = Path.Combine(basePath, "Mydatabase");
CopyDatabase(finalPath);
}
public static void CopyDatabase(string databasePath)
{
var bytes = System.IO.File.ReadAllBytes(databasePath);
var fileCopyName = string.Format("/sdcard/Database_{0:dd-MM-yyyy_HH-mm-ss-tt}.db", System.DateTime.Now);
System.IO.File.WriteAllBytes(fileCopyName, bytes);
}
Did you add the two permissions listed below in your manifest file?
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
If you have confirmed that the above permissions are correctly being added, please try the code to export data from the app storage onto your SD Card:
private void Button_Clicked(object sender, EventArgs e)
{
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TodoSQLite.db3");
var bytes = File.ReadAllBytes(path);
var fileCopyName = string.Format("/sdcard/Database_{0:dd-MM-yyyy_HH-mm-ss-tt}.db", DateTime.Now);
File.WriteAllBytes(fileCopyName, bytes);
}
The issue was the path address. I fixed it by checking for the directory first to see if it exists, then I copy the database to the directory in a new/existing file. The issue I have now is that the file saves to phone but not the SD card, but I am just happy that the backup file is finally saving.
Below is the code is used to fix the issue:
private void CopyDBButton_Clicked(object sender, EventArgs e)
{
//Used to find the database in the special folder
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mydatabase");
//Used to locate the SD Card path
string path1 = Path.Combine("/sdcard/", Android.OS.Environment.DirectoryDownloads);
//Used to save the Database to a byte array
var bytes = File.ReadAllBytes(path);
//Used to check if the directory exists
if (!Directory.Exists(path1))
{
//Directory.CreateDirectory(filePathDir);
Console.WriteLine("Doesnt Exist");
}
else
{
Console.WriteLine("Does Exist");
//Used to create the name of the new Database backup file
var fileCopyName = string.Format(path1 + "/Database_{0:dd-MM-yyyy_HH-mm-ss-tt}.db", DateTime.Now);
//Write to the new database backup file
File.WriteAllBytes(fileCopyName, bytes);
}
}

Phone dialer issues in xamarin.plugins.messaging

I am new for Xamarin and I just wanted to directly make a phone call from my Xamarin app.
I just wanted to include the hashtag(#) symbol in the phone number as a string, but it doesn't include the symbol when the program is executed.
Here is the code,
private void Button_Clicked(object sender, EventArgs e)
{
var phoneDialer = CrossMessaging.Current.PhoneDialer;
if (phoneDialer.CanMakePhoneCall)
phoneDialer.MakePhoneCall("*999#");
}
Any help would be appreciated!
Have a look at this thread:
Specifically, if a URL contains the * or # characters, the Phone
application does not attempt to dial the corresponding phone number.
There is also an answer in Swift which says iOS11 now allows us to call number with * or # , I translate it to C# and you can have a try with dependency service:
In shared Project:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
DependencyService.Get<IPhoneCallTask>().DoPhoneCall();
}
}
public interface IPhoneCallTask
{
void DoPhoneCall();
}
In iOS Project:
[assembly: Dependency(typeof(phoneCall))]
namespace App591.iOS
{
class phoneCall : IPhoneCallTask
{
public void DoPhoneCall()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
NSString number = new NSString("*111*12345#");
NSString encode = number.CreateStringByAddingPercentEncoding(NSUrlUtilities_NSCharacterSet.UrlHostAllowedCharacterSet);
NSString header = new NSString("tel://");
string tmp = string.Format("{0}{1}", encode, header);
NSString urlTemp = new NSString(tmp);
if (UIApplication.SharedApplication.CanOpenUrl(new Uri(urlTemp)))
{
UIApplication.SharedApplication.OpenUrl(new Uri(urlTemp));
}
}
}
}
}

Is there a way to Alias a dead network path to a local directory in Windows 7?

I have a bunch of old Batch scripts that I may need to revive that have hundreds of references to a dead specific network path. Is there a way to alias \\myNetWorkPath.com\SomeFolder\SomeFolder2 to a specific local Windows 7 directory?
For example, \\myNetWorkPath.com\SomeFolder\SomeFolder2 alias to C:\SomeFolder2.
Again, \\myNetWorkPath.com\SomeFolder\SomeFolder2 is a dead (not working anymore) network path.
Please let me know if that doesn’t make any sense.
Thanks!
Following up on my "Pick a language and write a quick and dirty application that will change your code base." comment... Here's a bit of c# that could get your going.
static void Main(string[] args)
{
//foreach file you drop onto the compiled EXE
foreach (string item in args)
{
if (System.IO.File.Exists(item))//if the file path actually exists
{
ChangeThePath(item);
}
}
}
private static void ChangeThePath(string incomingFilePath)
{
string backupCopy = incomingFilePath + ".bck";
System.IO.File.Copy(incomingFilePath, backupCopy);//make a backup
string newPath = "c:\\This\\New\\Path\\Is\\Much\\Better";
string oldPath = "c:\\Than\\This\\Deprecated\\One";
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(incomingFilePath))
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(backupCopy))
{
string currentLine = string.Empty;
while ((currentLine = sr.ReadLine()) != null)
{
sw.WriteLine(currentLine.Replace(oldPath, newPath));
}
}
}
}

Windows Phone 7.1 -Saving path of photo taken by cameraCaputreTask

I'm building an app that should- among other things, let the user capture a picture and then save the picture and other info (like location of where this picture was taken -using GPS of the phone and etc...) on a DataBase.
Im using a string to save the pictures to the DataBase. So far so good. My problem is that after the user has captured a picture I can not find the path of the picture anyWhere (in order to display it later to the user )
I know I can display the picture if I use a image and not a string but then I am not able to save it to the DB.
Also I used the picture string (which should be the path of the picture ) to be the primaryKey column in my table and if the string is null this will be a problem for sure.
After checking on the internet I found out that you cannot use the GeoCoordinateWatcher (for GPS) on the emulator so I had to use a random place.
This led me into thinking that a picture taken by the emulator may not have a path??
Part of my code: (the Event of the camera and the bottun that saves everyting to DB)
void c_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show(e.ChosenPhoto.Length.ToString());
//Code to display the photo on the page in an image control named myImage.
BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
myImage.Source = bmp;//display the picture right after taking it. before saving to DB
p.UrlImage = bmp.UriSource.AbsolutePath;//Do not Work!
}
}
private void saveToDB_Click(object sender, RoutedEventArgs e)
{
p.Description = DesriptionList.SelectedValue.ToString();//description of the pic
p.Date = DateTime.Today;//date picture taken
GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher();
var myPosition = myWatcher.Position;
p.Location = myPosition.Location.Altitude+" "+myPosition.Location.Latitude;//do not work with emulator
p.Location = "Some Where Over The Rainbow";
MainPage.m._bl.addPic(p);//add pic to DB
MessageBox.Show("Added Successfully! :)");
NavigationService.Navigate(new Uri(#"/Intro.xaml", UriKind.Relative));//go to another page
}
}
my class:
[Table]
public class Picture
{
public Picture()
{
}
public Picture(string l, string d, string url, DateTime da)
{
Location = l;
Description = d;
UrlImage = url;
Date = da;
}
string location;
[Column]
public string Location
{
get { return location; }
set { location = value; }
}
string urlImage;
[Column (IsPrimaryKey=true)]
public string UrlImage
{
get { return urlImage; }
set { urlImage = value; }
}
DateTime date;
[Column]
public DateTime Date
{
get { return date; }
set { date = value; }
}
string description;
[Column]
public string Description
{
get { return description; }
set { description = value; }
}
}
}
Anyway- I would like to know if I can get the path in some way...
And also- if I cant get the path- does Windows have a "Better" emulator?
this emulator cant do much and this is quite annoying giving the fact I dont have a WP to check my apps on..
Thanks!
You already get the stream of the taken image in e.ChosenPhoto. You just need to save that.
var imageBytes = new byte[e.ChosenPhoto.Length];
e.ChosenPhoto.Read(imageBytes, 0, imageBytes.Length);
using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication()) {
using (var stream = isoFile.CreateFile("myImage.jpg")) {
stream.Write(imageBytes, 0, imageBytes.Length);
}
}
edit:
Regarding emulator, there is nothing wrong or limited about it.
The taken image is stored in a temp file that may vanish later on that's why you need to save it locally in your isolated storage if you want to display that image again.
Regarding GPS, you can use the additional tools (just click on the '>>' button on the right side of the emulator to set various settings that you find on an actual device such as accelerometer, location, network, etc.. For GeoWatcher you can define a set of points on the map that will be played back as if the device's actual GPS location was changing.

How do I prevent SoundEffect from playing before the page is fully loaded

In my windows phone 7 app I'm using the following code to navigate to a page
private void button2_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Views/Game.xaml, UriKind.RelativeOrAbsolute));
}
In the OnNavigatedTo event of Game.xaml.cs I use the following code to play two wav files one after another. In order for me to prevent both audio play at the same time, I use while loop to wait until the first audio is finish before the second file is played. I believe this is what causing the first audio to play before the game page is displayed. Is there a better way of doing this?
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
playAudio("intro.wav");
while (MySoundEffect.State == SoundState.Playing)
{
}
playAudio("firstQuestion.wav");
base.OnNavigatedTo(e);
}
The following is the code for playAudio.
protected void playAudio(string fileName)
{
Stream stream = TitleContainer.OpenStream("audio/" + fileName);
SoundEffect effect = SoundEffect.FromStream(stream);
MySoundEffect = effect.CreateInstance();
FrameworkDispatcher.Update();
MySoundEffect.Play();
}
MySoundEffect is a property of the Game class.
private SoundEffectInstance _MySoundEffect;
public SoundEffectInstance MySoundEffect
{
get { return _MySoundEffect; }
set { _MySoundEffect = value; }
}
Whenever user click the button, the sound
To answer your question in the title, you could try the same with the
Loaded
event handler instead of the OnNavigateTo. This way, your audio files will start playing
only after the page is loaded.

Resources