shayne / PowerDimmer

Distraction dimmer for Windows ala HazeOver/LeDimmer
MIT License
74 stars 9 forks source link

Settings file permissions error #5

Open MisteryMonster opened 2 years ago

MisteryMonster commented 2 years ago

when changing light:

************** Exception Text **************
System.IO.IOException: Unable to move the replacement file to the file to be replaced. The file to be replaced has retained its original name.
   at System.IO.FileSystem.ReplaceFile(String sourceFullPath, String destFullPath, String destBackupFullPath, Boolean ignoreMetadataErrors)
   at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName, Boolean ignoreMetadataErrors)
   at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName)
   at Config.Net.Json.Stores.JsonFileConfigStore.WriteJsonFile() in /_/src/Config.Net.Json/Stores/JsonFileConfigStore.cs:line 165
   at Config.Net.Json.Stores.JsonFileConfigStore.Write(String key, String value) in /_/src/Config.Net.Json/Stores/JsonFileConfigStore.cs:line 126
   at Config.Net.Core.IoHandler.Write(Type baseType, String path, Object value) in /_/src/Config.Net/Core/IoHandler.cs:line 38
   at Config.Net.Core.DynamicWriter.WriteProperty(PropertyResultBox pbox, Object[] arguments) in /_/src/Config.Net/Core/DynamicWriter.cs:line 32
   at Config.Net.Core.DynamicWriter.Write(ResultBox rbox, Object[] arguments) in /_/src/Config.Net/Core/DynamicWriter.cs:line 19
   at Config.Net.Core.InterfaceInterceptor.Intercept(IInvocation invocation) in /_/src/Config.Net/Core/InterfaceInterceptor.cs:line 63
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.ISettingsProxy.set_Brightness(Int32 value)
   at PowerDimmer.TrackBarMenuItem.<>c__DisplayClass1_1.<.ctor>b__1(Object o, EventArgs s) in C:\Users\virtual\Desktop\dimmer\NotifyIconController.cs:line 117
   at System.Windows.Forms.TrackBar.OnValueChanged(EventArgs e)
   at PowerDimmer.TrackBarWithoutFocus.WndProc(Message& m) in C:\Users\virtual\Desktop\dimmer\NotifyIconController.cs:line 66
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

when disable dimming by tray:

System.IO.IOException: Unable to move the replacement file to the file to be replaced. The file to be replaced has retained its original name.
   at System.IO.FileSystem.ReplaceFile(String sourceFullPath, String destFullPath, String destBackupFullPath, Boolean ignoreMetadataErrors)
   at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName, Boolean ignoreMetadataErrors)
   at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName)
   at Config.Net.Json.Stores.JsonFileConfigStore.WriteJsonFile() in /_/src/Config.Net.Json/Stores/JsonFileConfigStore.cs:line 165
   at Config.Net.Json.Stores.JsonFileConfigStore.Write(String key, String value) in /_/src/Config.Net.Json/Stores/JsonFileConfigStore.cs:line 126
   at Config.Net.Core.IoHandler.Write(Type baseType, String path, Object value) in /_/src/Config.Net/Core/IoHandler.cs:line 38
   at Config.Net.Core.DynamicWriter.WriteProperty(PropertyResultBox pbox, Object[] arguments) in /_/src/Config.Net/Core/DynamicWriter.cs:line 32
   at Config.Net.Core.DynamicWriter.Write(ResultBox rbox, Object[] arguments) in /_/src/Config.Net/Core/DynamicWriter.cs:line 19
   at Config.Net.Core.InterfaceInterceptor.Intercept(IInvocation invocation) in /_/src/Config.Net/Core/InterfaceInterceptor.cs:line 63
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.ISettingsProxy.set_DimmingEnabled(Boolean value)
   at PowerDimmer.NotifyIconController.<>c__DisplayClass2_0.<.ctor>b__5(Boolean b) in C:\Users\virtual\Desktop\dimmer\NotifyIconController.cs:line 36
   at PowerDimmer.ToggleGenerateOption.InvokeHandlers(Boolean check) in C:\Users\virtual\Desktop\dimmer\NotifyIconBuilder.cs:line 181
   at PowerDimmer.ContextMenuStripBuilder.<>c__DisplayClass6_0.<AddToggle>b__0(Object _, EventArgs _) in C:\Users\virtual\Desktop\dimmer\NotifyIconBuilder.cs:line 60
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

when i hit CTRL+WIN+ALT+D it crash. I need to delete the settings.json to restart.

And the weird thing is, after startup, the dimming not work normally ( it light up every window I clicked and not getting dark). After the error Unhandled exception has occurred in a component in your application... show up, it works again.(Sorry I think I can easily move the bin folder to other PC! I'm wrong! works normally after I dotnet run

shayne commented 2 years ago

This is interesting. It looks like you have the app extracted in C:\Users\virtual\Desktop\dimmer. How are you running it when you get these errors? Are you using dotnet run or other means? It's looks like a permissions issue when trying to write out the settings.json. Let me know if you're doing anything different that might cause this issue.

MisteryMonster commented 2 years ago

I just dotnet run in the extracted folder and get these error. So I went to VirtualBox to test. The folder C:\Users\virtual\Desktop\dimmer is I testing in VirtualBox and works perfectly. And then I try to move the bin folder to my PC but get no luck, still facing the issue.

MisteryMonster commented 1 year ago

I can only run it in Volume C, maybe is about File.Replace. It will throw an exception if source and destination files are on the different volumes.

TTSKarlsson commented 1 year ago

I can confirm it only works if the executable and settings.json are on C:

AlanDrake commented 1 month ago

Remove the Config.Net.Json package and update Config.Net to the latest. That will fix the issue with settings.json when running from different drives.