/// <summary> /// Speichert die Datei ab /// </summary> /// <param name="saveToFile">Dateipfad</param> public void SaveToFile(L3dFilePath outputPath) { if (OwnPath != outputPath && !L3dFilePath.IsNullOrEmpty(FilePicture)) { try { string newPath = Path.Combine(outputPath.Directory, outputPath.Filename + ".jpg"); File.Copy(FilePicture.AbsolutePath, newPath); FilePicture = new L3dFilePath(newPath); } catch (Exception) { FilePicture = new L3dFilePath(); } } XDocument xDoc = SaveToXmlDocument(GetRootPropsElement(outputPath), outputPath); string output = GetOutputString(xDoc); string tmpFile = TempFileUtility.GetTempFileName("tmp", 0, outputPath.Directory); if (File.Exists(outputPath.AbsolutePath)) { xDoc.Save(tmpFile); File.Replace(tmpFile, outputPath.AbsolutePath, null); } else { File.Delete(tmpFile); xDoc.Save(outputPath.AbsolutePath); } _lastSavedDoc = output; OwnPath = outputPath; }
public static void Main() { try { CultureInfo cInf = new CultureInfo(RegistrySettings.Default.UiCulture); Loksim3D.WetterEdit.Resources.Strings.Culture = cInf; } catch (ArgumentException ex) { MessageBox.Show("Invalid Language Settings " + RegistrySettings.Default.UiCulture + "\n" + ex.Message); } if (Environment.OSVersion.Version.Major >= 6 && RegistrySettings.Default.DefaultAdminStartMode != RegistrySettings.AdminStartMode.DoNotStartAsAdmin) { // Unter Vista oder höher prüfen ob wir in das Datenverzeichnis lt. paths.ini schreiben dürfen // Wenn nicht schauen wir ob wir als Admin ausgeführt werden // Wenn nicht als Admin ausgeführt => User fragen ob als Admin ausführen bzw in Optionen nachschauen was user möchte string datadir = L3dFilePath.LoksimDirectory.AbsolutePath; try { string file = TempFileUtility.GetTempFileName("l3d", 0, datadir /*Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)*/); File.Delete(file); } catch (Win32Exception ex) { if (ex.ErrorCode == TempFileUtility.ERROR_ACCESS_DENIED) { IntPtr tkHandle; IntPtr procHandle = Process.GetCurrentProcess().Handle; Win32Utility.OpenProcessToken(procHandle, (uint)System.Security.Principal.TokenAccessLevels.Read, out tkHandle); uint TokenInfLength = 0; bool Result; // first call gets lenght of TokenInformation Result = Win32Utility.GetTokenInformation(tkHandle, Win32Utility.TOKEN_INFORMATION_CLASS.TokenElevation, IntPtr.Zero, TokenInfLength, out TokenInfLength); IntPtr TokenInformation = Marshal.AllocHGlobal((int)TokenInfLength); Result = Win32Utility.GetTokenInformation(tkHandle, Win32Utility.TOKEN_INFORMATION_CLASS.TokenElevation, TokenInformation, TokenInfLength, out TokenInfLength); if (Result) { Win32Utility.TOKEN_ELEVATION TokenElevation = (Win32Utility.TOKEN_ELEVATION)Marshal.PtrToStructure(TokenInformation, typeof(Win32Utility.TOKEN_ELEVATION)); TaskDialog dlg = new TaskDialog { Caption = Strings.UacDlgCaption, InstructionText = Strings.UacDlgInstructionText, Text = Strings.UacDlgText, FooterCheckBoxChecked = false, FooterCheckBoxText = Strings.UacDlgCheckBoxText, Cancelable = false, }; TaskDialogButton btn = new TaskDialogButton { Text = Strings.UacDlgBtnAdmin, UseElevationIcon = true, Default = true }; btn.Click += (sender, e) => dlg.Close(TaskDialogResult.Yes); dlg.Controls.Add(btn); btn = new TaskDialogButton { Text = Strings.UacDlgBtnNoAdmin }; btn.Click += (sender, e) => dlg.Close(TaskDialogResult.No); dlg.Controls.Add(btn); if (RegistrySettings.Default.DefaultAdminStartMode == RegistrySettings.AdminStartMode.StartAsAdmin || dlg.Show() == TaskDialogResult.Yes) { if (dlg.FooterCheckBoxChecked.GetValueOrDefault(false)) { RegistrySettings.Default.DefaultAdminStartMode = RegistrySettings.AdminStartMode.StartAsAdmin; } ProcessStartInfo info = new ProcessStartInfo(); info.FileName = System.Reflection.Assembly.GetCallingAssembly().Location; info.UseShellExecute = true; info.Verb = "runas"; // Provides Run as Administrator info.Arguments = EscapeCommandLineArguments(Environment.GetCommandLineArgs()); Process.Start(info); Marshal.FreeHGlobal(TokenInformation); return; } else if (RegistrySettings.Default.DefaultAdminStartMode == RegistrySettings.AdminStartMode.Ask && dlg.FooterCheckBoxChecked.GetValueOrDefault(false)) { RegistrySettings.Default.DefaultAdminStartMode = RegistrySettings.AdminStartMode.DoNotStartAsAdmin; } } Marshal.FreeHGlobal(TokenInformation); } } } // Der Editor soll pro Installation nur 1x gestartet werden können. // Hat der User mehrere Editoren in unterschiedlichen Verzeichnissen oder mit unterschiedlichen Namen, kann er diese jeweils 1x starten // Deshalb ist in der Unique-ID auch noch die Assembly Location kodiert if (SingleInstance <App> .InitializeAsFirstInstance(Unique + "-" + System.Reflection.Assembly.GetCallingAssembly().Location.GetHashCode())) { var application = new App(); application.InitializeComponent(); application.Run(); // Allow single instance code to perform cleanup operations SingleInstance <App> .Cleanup(); } }